X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmessage.cpp;h=f8b64e58ac4a964eaa150480b84cdcb06cc9b77a;hb=6836fbb5db8464f56e682989996b2210b14231d0;hp=4bc8cb63bb3bfd5a13905907870ff2383b614d4a;hpb=0574a75431d98ed64c5cc6291600bb3759b399a6;p=fms.git diff --git a/src/message.cpp b/src/message.cpp index 4bc8cb6..f8b64e5 100644 --- a/src/message.cpp +++ b/src/message.cpp @@ -183,7 +183,8 @@ void Message::HandleAdministrationMessage() } else { - origmessagetrust=m_minlocalmessagetrust; + //origmessagetrust=m_minlocalmessagetrust; + origmessagetrust=50; } if(origmess.ResultNull(3)==false) { @@ -191,7 +192,8 @@ void Message::HandleAdministrationMessage() } else { - origtrustlisttrust=m_minlocaltrustlisttrust; + //origtrustlisttrust=m_minlocaltrustlisttrust; + origtrustlisttrust=50; } origmessagetrust+=changemessagetrust; @@ -282,7 +284,8 @@ void Message::HandleChangeTrust() } else { - localmessagetrust=m_minlocalmessagetrust; + //localmessagetrust=m_minlocalmessagetrust; + localmessagetrust=50; } localmessagetrust+=m_changemessagetrustonreply; @@ -322,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); @@ -691,6 +695,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; @@ -702,37 +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); + } - 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;