X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmessage.cpp;h=f8b64e58ac4a964eaa150480b84cdcb06cc9b77a;hb=6836fbb5db8464f56e682989996b2210b14231d0;hp=5905021de147e290c95f86ec489832b6f7d6adb4;hpb=63376b2a82c3f6cdf2df56b1f134bd7df0aaab3a;p=fms.git diff --git a/src/message.cpp b/src/message.cpp index 5905021..f8b64e5 100644 --- a/src/message.cpp +++ b/src/message.cpp @@ -696,10 +696,27 @@ const bool Message::ParseNNTPMessage(const std::string &nntpmessage) m_body+=bodypart; } // add a binary file attachment - else if((*i)->GetName()!="" && (*i)->GetLength()>0 && (*i)->GetContent()) + 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()); - m_fileattachments.push_back(fileattachment((*i)->GetName(),data)); + 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)); } } @@ -712,49 +729,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); + } - // insert file attachments into database - st=m_db->Prepare("INSERT INTO tblFileInserts(MessageUUID,FileName,Size,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_data[0]),(*i).m_data.size()); + 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(); - st.Reset(); - } + 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); + } - HandleChangeTrust(); + } + 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;