version 0.2.20
[fms.git] / src / freenet / messagerequester.cpp
index 5b6d271..5c95cdb 100644 (file)
@@ -206,6 +206,25 @@ const bool MessageRequester::HandleAllData(FCPMessage &message)
 \r
                if(validmessage && savetoboardcount>0)\r
                {\r
+                       std::string nntpbody="";\r
+                       nntpbody=xml.GetBody();\r
+\r
+                       //add file keys/sizes to body\r
+                       std::vector<MessageXML::fileattachment> fileattachments=xml.GetFileAttachments();\r
+                       if(fileattachments.size()>0)\r
+                       {\r
+                               nntpbody+="\r\nAttachments";\r
+                       }\r
+                       for(std::vector<MessageXML::fileattachment>::iterator i=fileattachments.begin(); i!=fileattachments.end(); i++)\r
+                       {\r
+                               std::string sizestr="0";\r
+                               StringFunctions::Convert((*i).m_size,sizestr);\r
+\r
+                               nntpbody+="\r\n"+(*i).m_key;\r
+                               nntpbody+="\r\n"+sizestr+" bytes";\r
+                               nntpbody+="\r\n";\r
+                       }\r
+\r
                        st=m_db->Prepare("INSERT INTO tblMessage(IdentityID,FromName,MessageDate,MessageTime,Subject,MessageUUID,ReplyBoardID,Body,MessageIndex) VALUES(?,?,?,?,?,?,?,?,?);");\r
                        st.Bind(0,identityid);\r
                        st.Bind(1,GetIdentityName(identityid));\r
@@ -214,7 +233,7 @@ const bool MessageRequester::HandleAllData(FCPMessage &message)
                        st.Bind(4,xml.GetSubject());\r
                        st.Bind(5,xml.GetMessageID());\r
                        st.Bind(6,GetBoardID(xml.GetReplyBoard(),GetIdentityName(identityid)));\r
-                       st.Bind(7,xml.GetBody());\r
+                       st.Bind(7,nntpbody);\r
                        st.Bind(8,index);\r
                        inserted=st.Step(true);\r
                        int messageid=st.GetLastInsertRowID();\r
@@ -348,6 +367,7 @@ void MessageRequester::Initialize()
        {\r
                m_log->WriteLog(LogFile::LOGLEVEL_WARNING,"Option MaxBoardsPerMessage is currently set at "+tempval+".  This value might be incorrectly configured.");\r
        }\r
+\r
        Option::Instance()->Get("SaveMessagesFromNewBoards",tempval);\r
        if(tempval=="true")\r
        {\r
@@ -357,6 +377,17 @@ void MessageRequester::Initialize()
        {\r
                m_savemessagesfromnewboards=false;\r
        }\r
+\r
+       Option::Instance()->Get("LocalTrustOverridesPeerTrust",tempval);\r
+       if(tempval=="true")\r
+       {\r
+               m_localtrustoverrides=true;\r
+       }\r
+       else\r
+       {\r
+               m_localtrustoverrides=false;\r
+       }\r
+\r
 }\r
 \r
 void MessageRequester::PopulateIDList()\r
@@ -373,9 +404,19 @@ void MessageRequester::PopulateIDList()
 \r
        sql="SELECT tblIdentity.IdentityID,Day,RequestIndex ";\r
        sql+="FROM tblMessageRequests INNER JOIN tblIdentity ON tblMessageRequests.IdentityID=tblIdentity.IdentityID ";\r
-       sql+="WHERE (tblIdentity.LocalMessageTrust IS NULL OR tblIdentity.LocalMessageTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinLocalMessageTrust')) ";\r
-       sql+="AND FromMessageList='true' AND Found='false' AND Day>='"+date.Format("%Y-%m-%d")+"' ";\r
-       sql+="AND (tblIdentity.PeerMessageTrust IS NULL OR tblIdentity.PeerMessageTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinPeerMessageTrust')) ";\r
+       sql+="WHERE FromMessageList='true' AND Found='false' AND Day>='"+date.Format("%Y-%m-%d")+"' ";\r
+       if(m_localtrustoverrides==false)\r
+       {\r
+               sql+="AND (tblIdentity.LocalMessageTrust IS NULL OR tblIdentity.LocalMessageTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinLocalMessageTrust')) ";\r
+               sql+="AND (tblIdentity.PeerMessageTrust IS NULL OR tblIdentity.PeerMessageTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinPeerMessageTrust')) ";\r
+       }\r
+       else\r
+       {\r
+               sql+="AND (tblIdentity.LocalMessageTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinLocalMessageTrust') OR (tblIdentity.LocalMessageTrust IS NULL AND (tblIdentity.PeerMessageTrust IS NULL OR tblIdentity.PeerMessageTrust>=(SELECT OptionValue FROM tblOption WHERE Option='MinPeerMessageTrust')))) ";\r
+       }\r
+       sql+="AND tblIdentity.Name <> '' ";\r
+       // sort by day descending - in case there is a bunch of messages on a day that keep timing out, we will eventually get to the next day and hopefully find messages there\r
+       sql+="ORDER BY tblMessageRequests.Day DESC ";\r
        sql+=";";\r
 \r
        SQLite3DB::Statement st=m_db->Prepare(sql);\r
@@ -455,7 +496,7 @@ void MessageRequester::StartRequest(const std::string &requestid)
                message["Identifier"]=m_fcpuniquename+"|"+requestid+"|"+parts[0]+"|"+parts[1]+"|"+parts[2]+"|"+message["URI"];\r
                message["ReturnType"]="direct";\r
                message["MaxSize"]="1000000";           // 1 MB\r
-               message["MaxRetries"]="-1";                     // use new ULPR since we are fairly sure message exists since the author says it does\r
+               message["MaxRetries"]="-1";                     // use ULPR since we are fairly sure message exists since the author says it does\r
 \r
                m_fcp->SendMessage(message);\r
 \r