X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmessage.cpp;h=f4a6ea6eaba0dbb1c4f1253b1f3aefa64b4f0ab8;hb=4430e7762844c66428b6f822288beb71b7f82b95;hp=123d370e5752c2ee443c3470f7b3a1e69ac7f963;hpb=f60495a029c54358f82956482fe203fe2b7b5b23;p=fms.git diff --git a/src/message.cpp b/src/message.cpp index 123d370..f4a6ea6 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"; } @@ -123,8 +140,22 @@ void Message::HandleAdministrationMessage() { origmess.ResultInt(0,identityid); origmess.ResultText(1,identityname); - origmess.ResultInt(2,origmessagetrust); - origmess.ResultInt(3,origtrustlisttrust); + if(origmess.ResultNull(2)==false) + { + origmess.ResultInt(2,origmessagetrust); + } + else + { + origmessagetrust=50; + } + if(origmess.ResultNull(3)==false) + { + origmess.ResultInt(3,origtrustlisttrust); + } + else + { + origtrustlisttrust=50; + } origmessagetrust+=changemessagetrust; origtrustlisttrust+=changetrustlisttrust; @@ -192,8 +223,50 @@ 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); + if(st.ResultNull(1)==false) + { + st.ResultInt(1,localmessagetrust); + } + else + { + localmessagetrust=50; + } + + 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 +276,18 @@ void Message::Initialize() m_fromname=""; m_boards.clear(); m_inreplyto.clear(); + m_changemessagetrustonreply=0; + Option::Instance()->Get("ChangeMessageTrustOnReply",tempval); + StringFunctions::Convert(tempval,m_changemessagetrustonreply); + Option::Instance()->Get("AddNewPostFromIdentities",tempval); + if(tempval=="true") + { + m_addnewpostfromidentities=true; + } + else + { + m_addnewpostfromidentities=false; + } } const bool Message::Load(const long messageid, const long boardid) @@ -286,8 +371,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 +476,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 +583,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); @@ -507,7 +617,7 @@ const bool Message::ParseNNTPMessage(const std::string &nntpmessage) return true; } -void Message::StartFreenetInsert() +const bool Message::StartFreenetInsert() { MessageXML xml; @@ -520,6 +630,7 @@ void Message::StartFreenetInsert() 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)); @@ -538,12 +649,19 @@ void Message::StartFreenetInsert() // couldn't find identity with this name - insert a new identity if(!st.RowReturned()) { - DateTime now; - now.SetToGMTime(); - st=m_db->Prepare("INSERT INTO tblLocalIdentity(Name) VALUES(?);"); - st.Bind(0,m_fromname); - st.Step(true); - localidentityid=st.GetLastInsertRowID(); + 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 { @@ -556,4 +674,27 @@ void Message::StartFreenetInsert() st.Bind(2,xml.GetXML()); st.Step(); + HandleChangeTrust(); + + return true; + +} + +void Message::StripAdministrationBoards() +{ + SQLite3DB::Statement st=m_db->Prepare("SELECT tblBoard.BoardID FROM tblBoard INNER JOIN tblAdministrationBoard ON tblBoard.BoardID=tblAdministrationBoard.BoardID WHERE BoardName=?;"); + for(std::vector::iterator i=m_boards.begin(); i!=m_boards.end(); ) + { + st.Bind(0,(*i)); + st.Step(); + if(st.RowReturned()) + { + i=m_boards.erase(i); + } + else + { + i++; + } + st.Reset(); + } }