X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmessage.cpp;h=4c897e3c5c30f0a4c6bd7647d6ebc6d2c6617913;hb=59a5414ec47a2932a7802fcd1d98c4d80166564f;hp=526dbd2fc4ad1cd048dddf84bc3009bbeca37780;hpb=dec33c63afafabf83c3039e916725cac6faef9b3;p=fms.git diff --git a/src/message.cpp b/src/message.cpp index 526dbd2..4c897e3 100644 --- a/src/message.cpp +++ b/src/message.cpp @@ -18,12 +18,12 @@ #include #endif -Message::Message() +Message::Message(SQLite3DB::DB *db):IDatabase(db) { Initialize(); } -Message::Message(const long messageid) +Message::Message(SQLite3DB::DB *db, const long messageid):IDatabase(db) { Load(messageid); } @@ -49,6 +49,63 @@ const bool Message::CheckForAdministrationBoard(const std::vector & return false; } +const bool Message::Create(const long localidentityid, const long boardid, const std::string &subject, const std::string &body, const std::string &references) +{ + Initialize(); + + Poco::UUIDGenerator uuidgen; + Poco::UUID uuid; + + // get header info + // date is always set to now regardless of what message has + m_datetime=Poco::Timestamp(); + + // messageuuid is always a unique id we generate regardless of message message-id + try + { + uuid=uuidgen.createRandom(); + m_messageuuid=uuid.toString(); + StringFunctions::UpperCase(m_messageuuid,m_messageuuid); + } + catch(...) + { + m_log->fatal("Message::ParseNNTPMessage could not create UUID"); + } + + // get from + SQLite3DB::Statement st=m_db->Prepare("SELECT Name FROM tblLocalIdentity WHERE LocalIdentityID=?;"); + st.Bind(0,localidentityid); + st.Step(); + if(st.RowReturned()) + { + st.ResultText(0,m_fromname); + } + + // get boards posted to + std::string boardname=""; + SQLite3DB::Statement boardst=m_db->Prepare("SELECT BoardName FROM tblBoard WHERE BoardID=?;"); + boardst.Bind(0,boardid); + boardst.Step(); + if(boardst.RowReturned()) + { + boardst.ResultText(0,boardname); + } + + m_boards.push_back(boardname); + m_replyboardname=boardname; + + m_subject=subject; + + m_body=body; + + if(references!="") + { + m_inreplyto[0]=references; + } + + return true; +} + const int Message::FindLocalIdentityID(const std::string &name) { SQLite3DB::Statement st=m_db->Prepare("SELECT LocalIdentityID FROM tblLocalIdentity WHERE Name=?;"); @@ -250,7 +307,9 @@ void Message::HandleAdministrationMessage() insert.Bind(0,Poco::DateTimeFormatter::format(now,"%Y-%m-%d")); insert.Bind(1,Poco::DateTimeFormatter::format(now,"%H:%M:%S")); insert.Bind(2,identityname+" Trust Changed"); - insert.Bind(3,uuid.toString()); + std::string uuidstr=uuid.toString(); + StringFunctions::UpperCase(uuidstr,uuidstr); + insert.Bind(3,uuidstr); insert.Bind(4,boardid); insert.Bind(5,messagebody); insert.Step(true); @@ -341,9 +400,11 @@ void Message::Initialize() m_inreplyto.clear(); m_fileattachments.clear(); m_changemessagetrustonreply=0; - Option::Instance()->Get("ChangeMessageTrustOnReply",tempval); + Option option(m_db); + + option.Get("ChangeMessageTrustOnReply",tempval); StringFunctions::Convert(tempval,m_changemessagetrustonreply); - Option::Instance()->Get("AddNewPostFromIdentities",tempval); + option.Get("AddNewPostFromIdentities",tempval); if(tempval=="true") { m_addnewpostfromidentities=true; @@ -353,10 +414,10 @@ void Message::Initialize() m_addnewpostfromidentities=false; } tempval="50"; - Option::Instance()->Get("MinLocalMessageTrust",tempval); + option.Get("MinLocalMessageTrust",tempval); StringFunctions::Convert(tempval,m_minlocalmessagetrust); tempval="51"; - Option::Instance()->Get("MinLocalTrustListTrust",tempval); + option.Get("MinLocalTrustListTrust",tempval); StringFunctions::Convert(tempval,m_minlocaltrustlisttrust); } @@ -557,6 +618,8 @@ const bool Message::ParseNNTPMessage(const std::string &nntpmessage) try { uuid=uuidgen.createRandom(); + m_messageuuid=uuid.toString(); + StringFunctions::UpperCase(m_messageuuid,m_messageuuid); } catch(...) { @@ -635,6 +698,12 @@ const bool Message::ParseNNTPMessage(const std::string &nntpmessage) // remove any path folding m_replyboardname=StringFunctions::Replace(m_replyboardname,"\r\n",""); m_replyboardname=StringFunctions::Replace(m_replyboardname,"\t",""); + std::vector parts; + StringFunctions::Split(m_replyboardname,",",parts); + if(parts.size()>1) + { + m_replyboardname=parts[0]; + } } else { @@ -674,31 +743,34 @@ const bool Message::ParseNNTPMessage(const std::string &nntpmessage) std::string temp=mime.GetFieldValue("References"); // remove any path folding temp=StringFunctions::Replace(temp,"\r\n",""); - temp=StringFunctions::Replace(temp,"\t",""); + temp=StringFunctions::Replace(temp,"\t"," "); std::vector parts; int count=0; StringFunctions::SplitMultiple(temp,", \t",parts); for(std::vector::reverse_iterator i=parts.rbegin(); i!=parts.rend(); i++) { - // get rid of < and > and any whitespace - (*i)=StringFunctions::Replace((*i),"<",""); - (*i)=StringFunctions::Replace((*i),">",""); - (*i)=StringFunctions::TrimWhitespace((*i)); - /* - // erase @ and everything after - if((*i).find("@")!=std::string::npos) - { - (*i).erase((*i).find("@")); - } - */ - // only erase after @ if message is old type with @freenetproject.org - if((*i).find("@freenetproject.org")!=std::string::npos) - { - (*i).erase((*i).find("@")); - } - if((*i)!="") + if((*i).size()>2) { - m_inreplyto[count++]=(*i); + // get rid of < and > and any whitespace + (*i)=StringFunctions::Replace((*i),"<",""); + (*i)=StringFunctions::Replace((*i),">",""); + (*i)=StringFunctions::TrimWhitespace((*i)); + /* + // erase @ and everything after + if((*i).find("@")!=std::string::npos) + { + (*i).erase((*i).find("@")); + } + */ + // only erase after @ if message is old type with @freenetproject.org + if((*i).find("@freenetproject.org")!=std::string::npos) + { + (*i).erase((*i).find("@")); + } + if((*i)!="") + { + m_inreplyto[count++]=(*i); + } } } }