X-Git-Url: https://git.pterodactylus.net/?p=fms.git;a=blobdiff_plain;f=src%2Fmessage.cpp;h=41add1081e9d0acca8ec5e8585cae1fea11c6b9e;hp=c15b5302b717ae11a89ed6824684e6188893a236;hb=52c0819bfc1d083c6e0738f75f0d7eeba521295a;hpb=6b896a9e1dc143bba86795be1e9336549db9b85f diff --git a/src/message.cpp b/src/message.cpp index c15b530..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 @@ -20,9 +21,38 @@ Message::Message(const long messageid) Load(messageid); } +const bool Message::CheckForAdministrationBoard(const std::vector &boards) +{ + std::string name; + SQLite3DB::Statement st=m_db->Prepare("SELECT BoardName FROM tblBoard INNER JOIN tblAdministrationBoard ON tblBoard.BoardID=tblAdministrationBoard.BoardID;"); + st.Step(); + + while(st.RowReturned()) + { + st.ResultText(0,name); + + if(std::find(boards.begin(),boards.end(),name)!=boards.end()) + { + return true; + } + + st.Step(); + } + + return false; +} + const std::string Message::GetNNTPArticleID() const { - return "<"+m_messageuuid+">"; + // 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 @@ -57,7 +87,15 @@ const std::string Message::GetNNTPHeaders() const { rval+=" "; } - rval+="<"+(*j).second+">"; + // 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"; } @@ -69,8 +107,145 @@ const std::string Message::GetNNTPHeaders() const return rval; } +void Message::HandleAdministrationMessage() +{ + // only continue if this message was actually a reply to another message + if(m_inreplyto.size()>0) + { + int boardid=0; + std::string boardname=""; + std::string identityname=""; + int identityid; + int changemessagetrust=0; + int changetrustlisttrust=0; + int origmessagetrust=0; + int origtrustlisttrust=0; + SQLite3DB::Statement st=m_db->Prepare("SELECT tblBoard.BoardID,BoardName,ModifyLocalMessageTrust,ModifyLocalTrustListTrust FROM tblBoard INNER JOIN tblAdministrationBoard ON tblBoard.BoardID=tblAdministrationBoard.BoardID;"); + st.Step(); + + while(st.RowReturned()) + { + st.ResultInt(0,boardid); + st.ResultText(1,boardname); + st.ResultInt(2,changemessagetrust); + st.ResultInt(3,changetrustlisttrust); + + if(std::find(m_boards.begin(),m_boards.end(),boardname)!=m_boards.end()) + { + SQLite3DB::Statement origmess=m_db->Prepare("SELECT tblIdentity.IdentityID,tblIdentity.Name,tblIdentity.LocalMessageTrust,tblIdentity.LocalTrustListTrust FROM tblIdentity INNER JOIN tblMessage ON tblIdentity.IdentityID=tblMessage.IdentityID WHERE tblMessage.MessageUUID=?;"); + origmess.Bind(0,m_inreplyto[0]); + origmess.Step(); + + if(origmess.RowReturned()) + { + origmess.ResultInt(0,identityid); + origmess.ResultText(1,identityname); + origmess.ResultInt(2,origmessagetrust); + origmess.ResultInt(3,origtrustlisttrust); + + origmessagetrust+=changemessagetrust; + origtrustlisttrust+=changetrustlisttrust; + + if(origmessagetrust<0) + { + origmessagetrust=0; + } + if(origmessagetrust>100) + { + origmessagetrust=100; + } + if(origtrustlisttrust<0) + { + origtrustlisttrust=0; + } + if(origtrustlisttrust>100) + { + origtrustlisttrust=100; + } + + // update new trust levels + SQLite3DB::Statement update=m_db->Prepare("UPDATE tblIdentity SET LocalMessageTrust=?, LocalTrustListTrust=? WHERE IdentityID=?;"); + update.Bind(0,origmessagetrust); + update.Bind(1,origtrustlisttrust); + update.Bind(2,identityid); + update.Step(); + + // insert message to show what id was changed and what current levels are + int lastid=0; + std::string messagebody; + std::string messagetruststr=""; + std::string trustlisttruststr=""; + UUIDGenerator uuid; + DateTime now; + now.SetToGMTime(); + StringFunctions::Convert(origmessagetrust,messagetruststr); + StringFunctions::Convert(origtrustlisttrust,trustlisttruststr); + messagebody="Trust Changed for "+identityname+"\r\n"; + messagebody+="Local Message Trust : "+messagetruststr+"\r\n"; + messagebody+="Local Trust List Trust : "+trustlisttruststr+"\r\n"; + SQLite3DB::Statement insert=m_db->Prepare("INSERT INTO tblMessage(FromName,MessageDate,MessageTime,Subject,MessageUUID,ReplyBoardID,Body) VALUES('FMS',?,?,?,?,?,?);"); + insert.Bind(0,now.Format("%Y-%m-%d")); + insert.Bind(1,now.Format("%H:%M:%S")); + insert.Bind(2,identityname+" Trust Changed"); + insert.Bind(3,uuid.Generate()); + insert.Bind(4,boardid); + insert.Bind(5,messagebody); + insert.Step(true); + lastid=insert.GetLastInsertRowID(); + + insert=m_db->Prepare("INSERT INTO tblMessageBoard(MessageID,BoardID) VALUES(?,?);"); + insert.Bind(0,lastid); + insert.Bind(1,boardid); + insert.Step(); + + m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"Message::HandleAdministrationMessage updated "+identityname+" to "+messagetruststr+" , "+trustlisttruststr); + + } + } + + st.Step(); + } + } + +} + +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=""; @@ -80,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) @@ -121,6 +299,9 @@ const bool Message::Load(const long messageid, const long boardid) st.ResultText(7,m_fromname); st.Finalize(); + // strip off any \r\n in subject + m_subject=StringFunctions::Replace(m_subject,"\r\n",""); + // get board list st=m_db->Prepare("SELECT tblBoard.BoardName FROM tblBoard INNER JOIN tblMessageBoard ON tblBoard.BoardID=tblMessageBoard.BoardID WHERE tblMessageBoard.MessageID=?;"); st.Bind(0,messageid); @@ -160,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()) @@ -179,10 +376,10 @@ const bool Message::Load(const std::string &messageuuid) const bool Message::LoadNext(const long messageid, const long boardid) { - std::string sql="SELECT MessageID FROM tblMessage WHERE MessageID>?"; + std::string sql="SELECT tblMessage.MessageID FROM tblMessage INNER JOIN tblMessageBoard ON tblMessage.MessageID=tblMessageBoard.MessageID WHERE tblMessage.MessageID>?"; if(boardid!=-1) { - sql+=" AND BoardID=?"; + sql+=" AND tblMessageBoard.BoardID=?"; } sql+=";"; @@ -209,12 +406,12 @@ const bool Message::LoadNext(const long messageid, const long boardid) const bool Message::LoadPrevious(const long messageid, const long boardid) { - std::string sql="SELECT MessageID FROM tblMessage WHERE MessageIDPrepare(sql); @@ -249,12 +446,16 @@ 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")) { m_fromname=mime.GetFieldValue("From"); + // remove any path folding + m_fromname=StringFunctions::Replace(m_fromname,"\r\n",""); // strip off everything between () and <> and any whitespace std::string::size_type startpos=m_fromname.find("("); std::string::size_type endpos; @@ -276,6 +477,18 @@ const bool Message::ParseNNTPMessage(const std::string &nntpmessage) } } m_fromname=StringFunctions::TrimWhitespace(m_fromname); + + // trim off " from beginning and end + if(m_fromname.size()>0 && m_fromname[0]=='\"') + { + m_fromname.erase(0,1); + } + if(m_fromname.size()>0 && m_fromname[m_fromname.size()-1]=='\"') + { + m_fromname.erase(m_fromname.size()-1,1); + } + + m_fromname=StringFunctions::TrimWhitespace(m_fromname); } else { @@ -285,6 +498,8 @@ const bool Message::ParseNNTPMessage(const std::string &nntpmessage) if(mime.GetFieldValue("Newsgroups")) { std::string temp=mime.GetFieldValue("Newsgroups"); + // remove any path folding + temp=StringFunctions::Replace(temp,"\r\n",""); std::vector parts; StringFunctions::SplitMultiple(temp,", \t",parts); for(std::vector::iterator i=parts.begin(); i!=parts.end(); i++) @@ -302,6 +517,8 @@ const bool Message::ParseNNTPMessage(const std::string &nntpmessage) if(mime.GetFieldValue("Followup-To")) { m_replyboardname=mime.GetFieldValue("Followup-To"); + // remove any path folding + m_replyboardname=StringFunctions::Replace(m_replyboardname,"\r\n",""); } else { @@ -314,6 +531,8 @@ const bool Message::ParseNNTPMessage(const std::string &nntpmessage) if(mime.GetFieldValue("Subject")) { m_subject=mime.GetFieldValue("Subject"); + // remove any path folding + m_subject=StringFunctions::Replace(m_subject,"\r\n",""); } else { @@ -323,14 +542,29 @@ const bool Message::ParseNNTPMessage(const std::string &nntpmessage) if(mime.GetFieldValue("References")) { std::string temp=mime.GetFieldValue("References"); + // remove any path folding + temp=StringFunctions::Replace(temp,"\r\n",""); std::vector parts; int count=0; StringFunctions::SplitMultiple(temp,", \t",parts); for(std::vector::reverse_iterator i=parts.rbegin(); i!=parts.rend(); i++) { + // get rid of < and > and any whitespace (*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); @@ -355,6 +589,7 @@ const bool Message::ParseNNTPMessage(const std::string &nntpmessage) void Message::StartFreenetInsert() { + MessageXML xml; int localidentityid=-1; @@ -401,4 +636,6 @@ void Message::StartFreenetInsert() st.Bind(2,xml.GetXML()); st.Step(); + HandleChangeTrust(); + }