X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmessage.cpp;h=d7aaf3fc12bf26896b5cccedb999fa6a08ed00ad;hb=44f964d9b2b2d55a5b5672e9297717bd25fa8ee2;hp=eea0633477f6d423d609e0ff33f7aa4bd1fa12ee;hpb=b4f4686250878cdf4fcb2986a2ea6546cba867d1;p=fms.git diff --git a/src/message.cpp b/src/message.cpp index eea0633..d7aaf3f 100644 --- a/src/message.cpp +++ b/src/message.cpp @@ -7,6 +7,10 @@ #include +#ifdef DO_CHARSET_CONVERSION + #include "../include/charsetconverter.h" +#endif + #ifdef XMEM #include #endif @@ -179,7 +183,8 @@ void Message::HandleAdministrationMessage() } else { - origmessagetrust=m_minlocalmessagetrust; + //origmessagetrust=m_minlocalmessagetrust; + origmessagetrust=50; } if(origmess.ResultNull(3)==false) { @@ -187,7 +192,8 @@ void Message::HandleAdministrationMessage() } else { - origtrustlisttrust=m_minlocaltrustlisttrust; + //origtrustlisttrust=m_minlocaltrustlisttrust; + origtrustlisttrust=50; } origmessagetrust+=changemessagetrust; @@ -278,7 +284,8 @@ void Message::HandleChangeTrust() } else { - localmessagetrust=m_minlocalmessagetrust; + //localmessagetrust=m_minlocalmessagetrust; + localmessagetrust=50; } localmessagetrust+=m_changemessagetrustonreply; @@ -318,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); @@ -611,6 +619,19 @@ 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",""); +#if DO_CHARSET_CONVERSION + if(mime.GetFieldCharset("Subject")) + { + std::string charset=mime.GetFieldCharset("Subject"); + CharsetConverter ccv; + if(charset!="" && charset!="UTF-8" && ccv.SetConversion(charset,"UTF-8")) + { + std::string output=""; + ccv.Convert(m_subject,output); + m_subject=output; + } + } +#endif } else { @@ -658,7 +679,44 @@ const bool Message::ParseNNTPMessage(const std::string &nntpmessage) { if((*i)->IsText() && (*i)->GetContent()) { - m_body+=(char *)(*i)->GetContent(); + std::string bodypart=(char *)(*i)->GetContent(); +#ifdef DO_CHARSET_CONVERSION + std::string charset=(*i)->GetCharset(); + if(charset!="" && charset!="UTF-8") + { + CharsetConverter ccv; + if(ccv.SetConversion(charset,"UTF-8")) + { + std::string output=""; + ccv.Convert(bodypart,output); + bodypart=output; + } + } +#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)); } } @@ -689,35 +747,6 @@ const bool Message::StartFreenetInsert() xml.AddInReplyTo((*j).first,(*j).second); } - - // find identity to insert with - /* - SQLite3DB::Statement st=m_db->Prepare("SELECT LocalIdentityID FROM tblLocalIdentity WHERE Name=?;"); - st.Bind(0,m_fromname); - st.Step(); - - // couldn't find identity with this name - insert a new identity - if(!st.RowReturned()) - { - if(m_addnewpostfromidentities==true) - { - DateTime now; - now.SetToGMTime(); - st=m_db->Prepare("INSERT INTO tblLocalIdentity(Name) VALUES(?);"); - st.Bind(0,m_fromname); - st.Step(true); - localidentityid=st.GetLastInsertRowID(); - } - else - { - return false; - } - } - else - { - st.ResultInt(0,localidentityid); - } - */ localidentityid=FindLocalIdentityID(m_fromname); if(localidentityid==-1) { @@ -730,6 +759,19 @@ const bool Message::StartFreenetInsert() st.Bind(2,xml.GetXML()); 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; @@ -745,6 +787,10 @@ void Message::StripAdministrationBoards() st.Step(); if(st.RowReturned()) { + if(m_replyboardname==(*i)) + { + m_replyboardname=""; + } i=m_boards.erase(i); } else @@ -753,4 +799,8 @@ void Message::StripAdministrationBoards() } st.Reset(); } + if(m_replyboardname=="" && m_boards.begin()!=m_boards.end()) + { + m_replyboardname=(*m_boards.begin()); + } }