X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmessage.cpp;h=123d370e5752c2ee443c3470f7b3a1e69ac7f963;hb=f60495a029c54358f82956482fe203fe2b7b5b23;hp=c15b5302b717ae11a89ed6824684e6188893a236;hpb=6b896a9e1dc143bba86795be1e9336549db9b85f;p=fms.git diff --git a/src/message.cpp b/src/message.cpp index c15b530..123d370 100644 --- a/src/message.cpp +++ b/src/message.cpp @@ -20,9 +20,30 @@ 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+">"; + return "<"+m_messageuuid+"@freenetproject.org>"; } const std::string Message::GetNNTPBody() const @@ -57,7 +78,7 @@ const std::string Message::GetNNTPHeaders() const { rval+=" "; } - rval+="<"+(*j).second+">"; + rval+="<"+(*j).second+"@freenetproject.org>"; } rval+="\r\n"; } @@ -69,6 +90,108 @@ 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::Initialize() { m_messageid=-1; @@ -121,6 +244,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); @@ -179,10 +305,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 +335,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); @@ -255,6 +381,8 @@ const bool Message::ParseNNTPMessage(const std::string &nntpmessage) 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 +404,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 +425,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 +444,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 +458,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 +469,22 @@ 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("@")); + } if((*i)!="") { m_inreplyto[count++]=(*i); @@ -355,6 +509,7 @@ const bool Message::ParseNNTPMessage(const std::string &nntpmessage) void Message::StartFreenetInsert() { + MessageXML xml; int localidentityid=-1;