X-Git-Url: https://git.pterodactylus.net/?p=fms.git;a=blobdiff_plain;f=src%2Fmessage.cpp;h=41add1081e9d0acca8ec5e8585cae1fea11c6b9e;hp=123d370e5752c2ee443c3470f7b3a1e69ac7f963;hb=52c0819bfc1d083c6e0738f75f0d7eeba521295a;hpb=df316253862dc50e8e5a790d9634ef90be37badb diff --git a/src/message.cpp b/src/message.cpp index 123d370..41add10 100644 --- a/src/message.cpp +++ b/src/message.cpp @@ -3,6 +3,7 @@ #include "../include/uuidgenerator.h" #include "../include/stringfunctions.h" #include "../include/freenet/messagexml.h" +#include "../include/option.h" #include @@ -43,7 +44,15 @@ const bool Message::CheckForAdministrationBoard(const std::vector & const std::string Message::GetNNTPArticleID() const { - return "<"+m_messageuuid+"@freenetproject.org>"; + // old message - before 0.1.12 - doesn't have @domain so add @freenetproject.org + if(m_messageuuid.find("@")==std::string::npos) + { + return "<"+m_messageuuid+"@freenetproject.org>"; + } + else + { + return "<"+m_messageuuid+">"; + } } const std::string Message::GetNNTPBody() const @@ -78,7 +87,15 @@ const std::string Message::GetNNTPHeaders() const { rval+=" "; } - rval+="<"+(*j).second+"@freenetproject.org>"; + // old message - before 0.1.12 - doesn't have @domain so add @freenetproject.org + if((*j).second.find("@")==std::string::npos) + { + rval+="<"+(*j).second+"@freenetproject.org>"; + } + else + { + rval+="<"+(*j).second+">"; + } } rval+="\r\n"; } @@ -192,8 +209,43 @@ void Message::HandleAdministrationMessage() } +void Message::HandleChangeTrust() +{ + if(m_changemessagetrustonreply!=0 && m_inreplyto.size()>0) + { + SQLite3DB::Statement st=m_db->Prepare("SELECT tblIdentity.IdentityID,tblIdentity.LocalMessageTrust FROM tblIdentity INNER JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID WHERE tblMessage.MessageUUID=?;"); + st.Bind(0,m_inreplyto[0]); + st.Step(); + if(st.RowReturned()) + { + int identityid=0; + int localmessagetrust=0; + + st.ResultInt(0,identityid); + st.ResultInt(1,localmessagetrust); + + localmessagetrust+=m_changemessagetrustonreply; + if(localmessagetrust<0) + { + localmessagetrust=0; + } + if(localmessagetrust>100) + { + localmessagetrust=100; + } + + SQLite3DB::Statement st2=m_db->Prepare("UPDATE tblIdentity SET LocalMessageTrust=? WHERE IdentityID=?;"); + st2.Bind(0,localmessagetrust); + st2.Bind(1,identityid); + st2.Step(); + + } + } +} + void Message::Initialize() { + std::string tempval=""; m_messageid=-1; m_messageuuid=""; m_subject=""; @@ -203,6 +255,9 @@ void Message::Initialize() m_fromname=""; m_boards.clear(); m_inreplyto.clear(); + m_changemessagetrustonreply=0; + Option::Instance()->Get("ChangeMessageTrustOnReply",tempval); + StringFunctions::Convert(tempval,m_changemessagetrustonreply); } const bool Message::Load(const long messageid, const long boardid) @@ -286,8 +341,24 @@ const bool Message::Load(const long messageid, const long boardid) const bool Message::Load(const std::string &messageuuid) { + + std::string uuid=messageuuid; + + if(uuid.size()>0 && uuid[0]=='<') + { + uuid.erase(0,1); + } + if(uuid.size()>0 && uuid[uuid.size()-1]=='>') + { + uuid.erase(uuid.size()-1); + } + if(uuid.find("@freenetproject.org")!=std::string::npos) + { + uuid.erase(uuid.find("@freenetproject.org")); + } + SQLite3DB::Statement st=m_db->Prepare("SELECT MessageID FROM tblMessage WHERE MessageUUID=?;"); - st.Bind(0,messageuuid); + st.Bind(0,uuid); st.Step(); if(st.RowReturned()) @@ -375,8 +446,10 @@ const bool Message::ParseNNTPMessage(const std::string &nntpmessage) // get header info // date is always set to now regardless of what message has m_datetime.SetToGMTime(); + // messageuuid is always a unique id we generate regardless of message message-id m_messageuuid=uuid.Generate(); + // get from if(mime.GetFieldValue("From")) { @@ -480,11 +553,18 @@ const bool Message::ParseNNTPMessage(const std::string &nntpmessage) (*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); @@ -556,4 +636,6 @@ void Message::StartFreenetInsert() st.Bind(2,xml.GetXML()); st.Step(); + HandleChangeTrust(); + }