X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmessage.cpp;h=8281db7a67312fbcf931138d3e6ce91025c897bf;hb=1230cc420c955e75051d011d964bc68f061ba08c;hp=d2693f58fa3a54229e9aeceb90b6202013d9cc00;hpb=e773b0ecb8a35c67cde5b2e82bbebb05224f34d0;p=fms.git diff --git a/src/message.cpp b/src/message.cpp index d2693f5..8281db7 100644 --- a/src/message.cpp +++ b/src/message.cpp @@ -325,6 +325,7 @@ void Message::Initialize() m_fromname=""; m_boards.clear(); m_inreplyto.clear(); + m_fileattachments.clear(); m_changemessagetrustonreply=0; Option::Instance()->Get("ChangeMessageTrustOnReply",tempval); StringFunctions::Convert(tempval,m_changemessagetrustonreply); @@ -541,6 +542,7 @@ const bool Message::ParseNNTPMessage(const std::string &nntpmessage) m_fromname=mime.GetFieldValue("From"); // remove any path folding m_fromname=StringFunctions::Replace(m_fromname,"\r\n",""); + m_fromname=StringFunctions::Replace(m_fromname,"\t",""); // strip off everything between () and <> and any whitespace std::string::size_type startpos=m_fromname.find("("); std::string::size_type endpos; @@ -585,6 +587,7 @@ const bool Message::ParseNNTPMessage(const std::string &nntpmessage) std::string temp=mime.GetFieldValue("Newsgroups"); // remove any path folding temp=StringFunctions::Replace(temp,"\r\n",""); + temp=StringFunctions::Replace(temp,"\t",""); std::vector parts; StringFunctions::SplitMultiple(temp,", \t",parts); for(std::vector::iterator i=parts.begin(); i!=parts.end(); i++) @@ -604,6 +607,7 @@ const bool Message::ParseNNTPMessage(const std::string &nntpmessage) m_replyboardname=mime.GetFieldValue("Followup-To"); // remove any path folding m_replyboardname=StringFunctions::Replace(m_replyboardname,"\r\n",""); + m_replyboardname=StringFunctions::Replace(m_replyboardname,"\t",""); } else { @@ -618,6 +622,7 @@ const bool Message::ParseNNTPMessage(const std::string &nntpmessage) m_subject=mime.GetFieldValue("Subject"); // remove any path folding m_subject=StringFunctions::Replace(m_subject,"\r\n",""); + m_subject=StringFunctions::Replace(m_subject,"\t",""); #if DO_CHARSET_CONVERSION if(mime.GetFieldCharset("Subject")) { @@ -642,6 +647,7 @@ 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",""); std::vector parts; int count=0; StringFunctions::SplitMultiple(temp,", \t",parts); @@ -694,6 +700,29 @@ const bool Message::ParseNNTPMessage(const std::string &nntpmessage) #endif m_body+=bodypart; } + // add a binary file attachment + else if(((*i)->GetName()!="" || (*i)->GetFilename()!="") && (*i)->GetLength()>0 && (*i)->GetContent()) + { + std::string filename=""; + std::string contenttype=""; + std::vector data((*i)->GetContent(),(*i)->GetContent()+(*i)->GetContentLength()); + if((*i)->GetContentType()) + { + contenttype=(*i)->GetContentType(); + // find first ; tab cr or lf and erase it and everything after it + std::string::size_type endpos=contenttype.find_first_of(";\t\r\n "); + if(endpos!=std::string::npos) + { + contenttype.erase(endpos); + } + } + filename=(*i)->GetFilename(); + if(filename=="") + { + filename=(*i)->GetName(); + } + m_fileattachments.push_back(fileattachment(filename,contenttype,data)); + } } return true; @@ -705,37 +734,87 @@ const bool Message::StartFreenetInsert() MessageXML xml; int localidentityid=-1; - xml.SetMessageID(m_messageuuid); - xml.SetSubject(m_subject); - xml.SetBody(m_body); - xml.SetReplyBoard(m_replyboardname); - xml.SetDate(m_datetime.Format("%Y-%m-%d")); - xml.SetTime(m_datetime.Format("%H:%M:%S")); - StripAdministrationBoards(); - for(std::vector::iterator i=m_boards.begin(); i!=m_boards.end(); i++) - { - xml.AddBoard((*i)); - } - - for(std::map::iterator j=m_inreplyto.begin(); j!=m_inreplyto.end(); j++) - { - xml.AddInReplyTo((*j).first,(*j).second); - } - localidentityid=FindLocalIdentityID(m_fromname); - if(localidentityid==-1) + if(m_boards.size()>0) { - return false; - } - SQLite3DB::Statement st=m_db->Prepare("INSERT INTO tblMessageInserts(LocalIdentityID,MessageUUID,MessageXML) VALUES(?,?,?);"); - st.Bind(0,localidentityid); - st.Bind(1,m_messageuuid); - st.Bind(2,xml.GetXML()); - st.Step(); + xml.SetMessageID(m_messageuuid); + xml.SetSubject(m_subject); + xml.SetBody(m_body); + xml.SetReplyBoard(m_replyboardname); + + for(std::vector::iterator i=m_boards.begin(); i!=m_boards.end(); i++) + { + xml.AddBoard((*i)); + } + + for(std::map::iterator j=m_inreplyto.begin(); j!=m_inreplyto.end(); j++) + { + xml.AddInReplyTo((*j).first,(*j).second); + } - HandleChangeTrust(); + localidentityid=FindLocalIdentityID(m_fromname); + if(localidentityid==-1) + { + return false; + } + + // add the message delay if there is one + SQLite3DB::Statement st=m_db->Prepare("SELECT MinMessageDelay,MaxMessageDelay FROM tblLocalIdentity WHERE LocalIdentityID=?;"); + st.Bind(0,localidentityid); + st.Step(); + if(st.RowReturned()) + { + int min=0; + int max=0; + st.ResultInt(0,min); + st.ResultInt(1,max); + + min<0 ? min=0 : false; + max<0 ? max=0 : false; + min>max ? min=max : false; + + if(min==max) + { + m_datetime.Add(0,min); + } + else if(max>min) + { + int delay=(rand()%(max-min))+min; + m_datetime.Add(0,delay); + } + + } + st.Finalize(); + + // set date in xml file AFTER we set the delay + xml.SetDate(m_datetime.Format("%Y-%m-%d")); + xml.SetTime(m_datetime.Format("%H:%M:%S")); + + st=m_db->Prepare("INSERT INTO tblMessageInserts(LocalIdentityID,MessageUUID,MessageXML,SendDate) VALUES(?,?,?,?);"); + st.Bind(0,localidentityid); + st.Bind(1,m_messageuuid); + st.Bind(2,xml.GetXML()); + st.Bind(3,m_datetime.Format("%Y-%m-%d %H:%M:%S")); + st.Step(); + + // insert file attachments into database + st=m_db->Prepare("INSERT INTO tblFileInserts(MessageUUID,FileName,Size,MimeType,Data) VALUES(?,?,?,?,?);"); + for(std::vector::iterator i=m_fileattachments.begin(); i!=m_fileattachments.end(); i++) + { + st.Bind(0,m_messageuuid); + st.Bind(1,(*i).m_filename); + st.Bind(2,(long)(*i).m_data.size()); + st.Bind(3,(*i).m_mimetype); + st.Bind(4,&((*i).m_data[0]),(*i).m_data.size()); + st.Step(); + st.Reset(); + } + + HandleChangeTrust(); + + } return true;