From 287d1a9679648094ad5f0575358b0b59dd8736fc Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 28 Jun 2014 14:08:24 +0000 Subject: [PATCH] patch 003 from rudiger git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.6-Mime@7414 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/retroshare/rsmsgs.h | 39 ++-- libretroshare/src/retroshare/rstypes.h | 1 + libretroshare/src/rsserver/p3msgs.cc | 26 +-- libretroshare/src/rsserver/p3msgs.h | 26 +-- libretroshare/src/serialiser/rsmsgitems.cc | 49 +++-- libretroshare/src/serialiser/rsmsgitems.h | 10 +- libretroshare/src/services/p3msgservice.cc | 188 +++++++++--------- libretroshare/src/services/p3msgservice.h | 41 ++-- retroshare-gui/src/gui/MessagesDialog.cpp | 92 +++++---- retroshare-gui/src/gui/MessagesDialog.h | 7 +- retroshare-gui/src/gui/NewsFeed.cpp | 4 +- retroshare-gui/src/gui/feeds/MsgItem.h | 2 +- .../src/gui/msgs/MessageComposer.cpp | 70 +++++-- retroshare-gui/src/gui/msgs/MessageComposer.h | 10 +- retroshare-gui/src/gui/msgs/MessageWidget.cpp | 111 +++++++---- retroshare-gui/src/gui/msgs/MessageWidget.h | 12 +- retroshare-gui/src/gui/msgs/MessageWindow.cpp | 6 +- 17 files changed, 386 insertions(+), 308 deletions(-) diff --git a/libretroshare/src/retroshare/rsmsgs.h b/libretroshare/src/retroshare/rsmsgs.h index 0d912e5a8..cbc61ffd1 100644 --- a/libretroshare/src/retroshare/rsmsgs.h +++ b/libretroshare/src/retroshare/rsmsgs.h @@ -95,7 +95,6 @@ typedef std::string ChatLobbyNickName ; typedef RsPeerId DistantChatPeerId ; typedef GRouterKeyIdType DistantMsgPeerId ; -typedef uint64_t MessageId ; class MsgAddress { @@ -139,8 +138,11 @@ class MsgAddress class MessageInfo : public mimetic::MimeEntity { + MessageInfo( const MessageInfo & ); public: - MessageInfo() {} + typedef std::string MimeMsgId; + + MessageInfo(); MessageInfo( const std::string & msg ){ setMessage( msg ); } class addr_iterator { @@ -172,6 +174,9 @@ public: const std::string toString() const; void addAddr( const MsgAddress & addr ); + RsMessageId getMessageId(); + + RsPeerId rspeerid_srcId; RsGxsId rsgxsid_srcId; @@ -185,7 +190,7 @@ class MsgInfoSummary public: MsgInfoSummary() {} - std::string msgId; + RsMessageId msgId; RsPeerId srcId; uint32_t msgflags; @@ -200,7 +205,7 @@ class MsgTagInfo public: MsgTagInfo() {} - std::string msgId; + RsMessageId msgId; std::list tagIds; }; @@ -322,22 +327,22 @@ virtual ~RsMsgs() { return; } /****************************************/ virtual bool getMessageSummaries(std::list &msgList) = 0; -virtual bool getMessage(const std::string &mId, MessageInfo &msg) = 0; +virtual bool getMessage(const RsMessageId &mId, MessageInfo &msg) = 0; virtual void getMessageCount(unsigned int *pnInbox, unsigned int *pnInboxNew, unsigned int *pnOutbox, unsigned int *pnDraftbox, unsigned int *pnSentbox, unsigned int *pnTrashbox) = 0; -virtual bool decryptMessage(const std::string& mId) = 0 ; +virtual bool decryptMessage(const RsMessageId& mId) = 0 ; virtual bool MessageSend(MessageInfo &info) = 0; virtual bool SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag) = 0; -virtual bool MessageToDraft(MessageInfo &info, const std::string &msgParentId) = 0; -virtual bool MessageToTrash(const std::string &mid, bool bTrash) = 0; -virtual bool getMsgParentId(const std::string &msgId, std::string &msgParentId) = 0; +virtual bool MessageToDraft(MessageInfo &info, const RsMessageId &msgParentId) = 0; +virtual bool MessageToTrash(const RsMessageId &mid, bool bTrash) = 0; +virtual bool getMsgParentId(const RsMessageId &msgId, RsMessageId &msgParentId) = 0; -virtual bool MessageDelete(const std::string &mid) = 0; -virtual bool MessageRead(const std::string &mid, bool unreadByUser) = 0; -virtual bool MessageReplied(const std::string &mid, bool replied) = 0; -virtual bool MessageForwarded(const std::string &mid, bool forwarded) = 0; -virtual bool MessageStar(const std::string &mid, bool mark) = 0; -virtual bool MessageLoadEmbeddedImages(const std::string &mid, bool load) = 0; +virtual bool MessageDelete(const RsMessageId &mid) = 0; +virtual bool MessageRead(const RsMessageId &mid, bool unreadByUser) = 0; +virtual bool MessageReplied(const RsMessageId &mid, bool replied) = 0; +virtual bool MessageForwarded(const RsMessageId &mid, bool forwarded) = 0; +virtual bool MessageStar(const RsMessageId &mid, bool mark) = 0; +virtual bool MessageLoadEmbeddedImages(const RsMessageId &mid, bool load) = 0; /* message tagging */ @@ -346,8 +351,8 @@ virtual bool getMessageTagTypes(MsgTagType& tags) = 0; virtual bool setMessageTagType(uint32_t tagId, std::string& text, uint32_t rgb_color) = 0; virtual bool removeMessageTagType(uint32_t tagId) = 0; -virtual bool getMessageTag(const std::string &msgId, MsgTagInfo& info) = 0; -virtual bool setMessageTag(const std::string &msgId, uint32_t tagId, bool set) = 0; +virtual bool getMessageTag(const RsMessageId &msgId, MsgTagInfo& info) = 0; +virtual bool setMessageTag(const RsMessageId &msgId, uint32_t tagId, bool set) = 0; virtual bool resetMessageStandardTagTypes(MsgTagType& tags) = 0; diff --git a/libretroshare/src/retroshare/rstypes.h b/libretroshare/src/retroshare/rstypes.h index 9db36aaab..106844a06 100644 --- a/libretroshare/src/retroshare/rstypes.h +++ b/libretroshare/src/retroshare/rstypes.h @@ -49,6 +49,7 @@ typedef SSLIdType RsPeerId ; typedef PGPIdType RsPgpId ; typedef Sha1CheckSum RsFileHash ; +typedef Sha1CheckSum RsMessageId ; const uint32_t FT_STATE_FAILED = 0x0000 ; const uint32_t FT_STATE_OKAY = 0x0001 ; diff --git a/libretroshare/src/rsserver/p3msgs.cc b/libretroshare/src/rsserver/p3msgs.cc index 360ce2000..e01a465a7 100644 --- a/libretroshare/src/rsserver/p3msgs.cc +++ b/libretroshare/src/rsserver/p3msgs.cc @@ -78,7 +78,7 @@ bool p3Msgs::getMessageSummaries(std::list &msgList) -bool p3Msgs::getMessage(const std::string &mid, MessageInfo &msg) +bool p3Msgs::getMessage(const RsMessageId &mid, MessageInfo &msg) { return mMsgSrv->getMessage(mid, msg); } @@ -96,7 +96,7 @@ bool p3Msgs::MessageSend(MessageInfo &info) return mMsgSrv->MessageSend(info); } -bool p3Msgs::decryptMessage(const std::string& mId) +bool p3Msgs::decryptMessage(const RsMessageId & mId) { return mMsgSrv->decryptMessage(mId); } @@ -114,24 +114,24 @@ bool p3Msgs::SystemMessage(const std::string &title, const std::string &message, return mMsgSrv->SystemMessage(title, message, systemFlag); } -bool p3Msgs::MessageToDraft(MessageInfo &info, const std::string &msgParentId) +bool p3Msgs::MessageToDraft(MessageInfo &info, const RsMessageId &msgParentId) { return mMsgSrv->MessageToDraft(info, msgParentId); } -bool p3Msgs::MessageToTrash(const std::string &mid, bool bTrash) +bool p3Msgs::MessageToTrash(const RsMessageId &mid, bool bTrash) { return mMsgSrv->MessageToTrash(mid, bTrash); } -bool p3Msgs::getMsgParentId(const std::string &msgId, std::string &msgParentId) +bool p3Msgs::getMsgParentId(const RsMessageId &msgId, RsMessageId &msgParentId) { return mMsgSrv->getMsgParentId(msgId, msgParentId); } /****************************************/ /****************************************/ -bool p3Msgs::MessageDelete(const std::string &mid) +bool p3Msgs::MessageDelete(const RsMessageId &mid) { //std::cerr << "p3Msgs::MessageDelete() "; //std::cerr << "mid: " << mid << std::endl; @@ -139,7 +139,7 @@ bool p3Msgs::MessageDelete(const std::string &mid) return mMsgSrv -> removeMsgId(mid); } -bool p3Msgs::MessageRead(const std::string &mid, bool unreadByUser) +bool p3Msgs::MessageRead(const RsMessageId &mid, bool unreadByUser) { //std::cerr << "p3Msgs::MessageRead() "; //std::cerr << "mid: " << mid << std::endl; @@ -147,17 +147,17 @@ bool p3Msgs::MessageRead(const std::string &mid, bool unreadByUser) return mMsgSrv -> markMsgIdRead(mid, unreadByUser); } -bool p3Msgs::MessageReplied(const std::string &mid, bool replied) +bool p3Msgs::MessageReplied(const RsMessageId &mid, bool replied) { return mMsgSrv->setMsgFlag(mid, replied ? RS_MSG_FLAGS_REPLIED : 0, RS_MSG_FLAGS_REPLIED); } -bool p3Msgs::MessageForwarded(const std::string &mid, bool forwarded) +bool p3Msgs::MessageForwarded(const RsMessageId &mid, bool forwarded) { return mMsgSrv->setMsgFlag(mid, forwarded ? RS_MSG_FLAGS_FORWARDED : 0, RS_MSG_FLAGS_FORWARDED); } -bool p3Msgs::MessageLoadEmbeddedImages(const std::string &mid, bool load) +bool p3Msgs::MessageLoadEmbeddedImages(const RsMessageId &mid, bool load) { return mMsgSrv->setMsgFlag(mid, load ? RS_MSG_FLAGS_LOAD_EMBEDDED_IMAGES : 0, RS_MSG_FLAGS_LOAD_EMBEDDED_IMAGES); } @@ -167,7 +167,7 @@ bool p3Msgs::getMessageTagTypes(MsgTagType& tags) return mMsgSrv->getMessageTagTypes(tags); } -bool p3Msgs::MessageStar(const std::string &mid, bool star) +bool p3Msgs::MessageStar(const RsMessageId &mid, bool star) { return mMsgSrv->setMsgFlag(mid, star ? RS_MSG_FLAGS_STAR : 0, RS_MSG_FLAGS_STAR); @@ -183,12 +183,12 @@ bool p3Msgs::removeMessageTagType(uint32_t tagId) return mMsgSrv->removeMessageTagType(tagId); } -bool p3Msgs::getMessageTag(const std::string &msgId, MsgTagInfo& info) +bool p3Msgs::getMessageTag(const RsMessageId &msgId, MsgTagInfo& info) { return mMsgSrv->getMessageTag(msgId, info); } -bool p3Msgs::setMessageTag(const std::string &msgId, uint32_t tagId, bool set) +bool p3Msgs::setMessageTag(const RsMessageId &msgId, uint32_t tagId, bool set) { return mMsgSrv->setMessageTag(msgId, tagId, set); } diff --git a/libretroshare/src/rsserver/p3msgs.h b/libretroshare/src/rsserver/p3msgs.h index 166fcb8ad..989367c12 100644 --- a/libretroshare/src/rsserver/p3msgs.h +++ b/libretroshare/src/rsserver/p3msgs.h @@ -55,29 +55,29 @@ class p3Msgs: public RsMsgs * @param msgList ref to list summarising client's msgs */ virtual bool getMessageSummaries(std::list &msgList); - virtual bool getMessage(const std::string &mId, MessageInfo &msg); + virtual bool getMessage(const RsMessageId &mId, MessageInfo &msg); virtual void getMessageCount(unsigned int *pnInbox, unsigned int *pnInboxNew, unsigned int *pnOutbox, unsigned int *pnDraftbox, unsigned int *pnSentbox, unsigned int *pnTrashbox); virtual bool MessageSend(MessageInfo &info); - virtual bool decryptMessage(const std::string& mid); + virtual bool decryptMessage(const RsMessageId &mid); virtual bool SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag); - virtual bool MessageToDraft(MessageInfo &info, const std::string &msgParentId); - virtual bool MessageToTrash(const std::string &mid, bool bTrash); - virtual bool MessageDelete(const std::string &mid); - virtual bool MessageRead(const std::string &mid, bool unreadByUser); - virtual bool MessageReplied(const std::string &mid, bool replied); - virtual bool MessageForwarded(const std::string &mid, bool forwarded); - virtual bool MessageStar(const std::string &mid, bool star); - virtual bool MessageLoadEmbeddedImages(const std::string &mid, bool load); - virtual bool getMsgParentId(const std::string &msgId, std::string &msgParentId); + virtual bool MessageToDraft(MessageInfo &info, const RsMessageId &msgParentId); + virtual bool MessageToTrash(const RsMessageId &mid, bool bTrash); + virtual bool MessageDelete(const RsMessageId &mid); + virtual bool MessageRead(const RsMessageId &mid, bool unreadByUser); + virtual bool MessageReplied(const RsMessageId &mid, bool replied); + virtual bool MessageForwarded(const RsMessageId &mid, bool forwarded); + virtual bool MessageStar(const RsMessageId &mid, bool star); + virtual bool MessageLoadEmbeddedImages(const RsMessageId &mid, bool load); + virtual bool getMsgParentId(const RsMessageId &msgId, RsMessageId &msgParentId); virtual bool getMessageTagTypes(MsgTagType& tags); virtual bool setMessageTagType(uint32_t tagId, std::string& text, uint32_t rgb_color); virtual bool removeMessageTagType(uint32_t tagId); - virtual bool getMessageTag(const std::string &msgId, MsgTagInfo& info); + virtual bool getMessageTag(const RsMessageId &msgId, MsgTagInfo& info); /* set == false && tagId == 0 --> remove all */ - virtual bool setMessageTag(const std::string &msgId, uint32_t tagId, bool set); + virtual bool setMessageTag(const RsMessageId &msgId, uint32_t tagId, bool set); virtual bool resetMessageStandardTagTypes(MsgTagType& tags); diff --git a/libretroshare/src/serialiser/rsmsgitems.cc b/libretroshare/src/serialiser/rsmsgitems.cc index 77667727d..bee043b29 100644 --- a/libretroshare/src/serialiser/rsmsgitems.cc +++ b/libretroshare/src/serialiser/rsmsgitems.cc @@ -1573,7 +1573,7 @@ uint32_t RsMsgItem::serial_size(bool m_bConfiguration) if (m_bConfiguration) { // serialise msgId too - s += 4; + s += GetTlvStringSize(msgId.toStdString()); } return s; @@ -1609,8 +1609,10 @@ bool RsMsgItem::serialise(void *data, uint32_t& pktsize,bool config) ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_MSG, mimeMessage); - if (config) // serialise msgId too - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_MSGID , msgId); + if( config ){ + std::string mId = msgId.toStdString(); + ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_MSGID , mId); + } if (offset != tlvsize) { @@ -1660,7 +1662,9 @@ RsMsgItem *RsMsgSerialiser::deserialiseMsgItem(void *data, uint32_t *pktsize) ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_MSG, item->mimeMessage); if (m_bConfiguration) { - GetTlvString(data, rssize, &offset, TLV_TYPE_STR_MSGID, item->msgId ); //use this line for backward compatibility + std::string mId; + GetTlvString(data, rssize, &offset, TLV_TYPE_STR_MSGID, mId ); //use this line for backward compatibility + item->msgId = RsMessageId( mId ); } if (offset != rssize) @@ -1883,7 +1887,7 @@ uint32_t RsMsgTags::serial_size(bool) { uint32_t s = 8; /* header */ - s += 4; /* msgId */ + s += msgId.serial_size(); s += tagIds.size() * 4; /* tagIds */ return s; @@ -1911,7 +1915,7 @@ bool RsMsgTags::serialise(void *data, uint32_t& pktsize,bool config) /* skip the header */ offset += 8; - ok &= setRawString(data,tlvsize,&offset, msgId); + ok &= setRawString(data,tlvsize,&offset, msgId.toStdString()); std::list::iterator mit = tagIds.begin(); for(;mit != tagIds.end(); mit++) @@ -1959,7 +1963,9 @@ RsMsgTags* RsMsgSerialiser::deserialiseMsgTagItem(void* data, uint32_t* pktsize) /* get mandatory parts first */ - ok &= getRawString(data, rssize, &offset, item->msgId); + std::string mId; + ok &= getRawString(data, rssize, &offset, mId); + item->msgId = RsMessageId( mId ); uint32_t tagId; while (offset != rssize) @@ -2019,7 +2025,7 @@ uint32_t RsMsgSrcId::serial_size(bool) { uint32_t s = 8; /* header */ - s += 4; + s += msgId.serial_size(); s += srcId.serial_size() ; return s; @@ -2048,8 +2054,8 @@ bool RsMsgSrcId::serialise(void *data, uint32_t& pktsize,bool config) /* skip the header */ offset += 8; - ok &= setRawString(data, tlvsize, &offset, msgId); - ok &= srcId.serialise(data, tlvsize, offset) ; + ok &= msgId.serialise(data, tlvsize, offset); + ok &= srcId.serialise(data, tlvsize, offset); if (offset != tlvsize) { @@ -2093,7 +2099,12 @@ RsMsgSrcId* RsMsgSerialiser::deserialiseMsgSrcIdItem(void* data, uint32_t* pktsi /* get mandatory parts first */ - ok &= getRawString(data, rssize, &offset, item->msgId ); + std::string mId; + ok &= getRawString(data, rssize, &offset, mId ); + item->msgId = RsMessageId( mId ); + + + ok &= item->srcId.deserialise(data, rssize, offset); if (offset != rssize) @@ -2145,8 +2156,8 @@ uint32_t RsMsgParentId::serial_size(bool) { uint32_t s = 8; /* header */ - s += 4; // srcId - s += 4; // msgParentId + s += msgId.SIZE_IN_BYTES; // srcId + s += msgParentId.SIZE_IN_BYTES; // msgParentId return s; } @@ -2173,8 +2184,8 @@ bool RsMsgParentId::serialise(void *data, uint32_t& pktsize,bool config) /* skip the header */ offset += 8; - ok &= setRawString(data, tlvsize, &offset, msgId); - ok &= setRawString(data, tlvsize, &offset, msgParentId); + ok &= setRawString(data, tlvsize, &offset, msgId.toStdString()); + ok &= setRawString(data, tlvsize, &offset, msgParentId.toStdString()); if (offset != tlvsize) { @@ -2218,8 +2229,12 @@ RsMsgParentId* RsMsgSerialiser::deserialiseMsgParentIdItem(void* data, uint32_t* /* get mandatory parts first */ - ok &= getRawString(data, rssize, &offset, item->msgId ); - ok &= getRawString(data, rssize, &offset, item->msgParentId ); + std::string mId, mPId; + ok &= getRawString(data, rssize, &offset, mId ); + ok &= getRawString(data, rssize, &offset, mPId ); + item->msgId = RsMessageId( mId ); + item->msgParentId = RsMessageId( mPId ); + if (offset != rssize) { diff --git a/libretroshare/src/serialiser/rsmsgitems.h b/libretroshare/src/serialiser/rsmsgitems.h index 2b1626d43..20488946b 100644 --- a/libretroshare/src/serialiser/rsmsgitems.h +++ b/libretroshare/src/serialiser/rsmsgitems.h @@ -507,7 +507,7 @@ class RsMsgItem: public RsMessageItem // ----------- Specific fields ------------- // uint32_t msgFlags; - std::string msgId; + RsMessageId msgId; uint32_t sendTime; uint32_t recvTime; @@ -551,7 +551,7 @@ public: // ----------- Specific fields ------------- // // - std::string msgId; + RsMessageId msgId; std::list tagIds; }; @@ -571,7 +571,7 @@ class RsMsgSrcId : public RsMessageItem // ----------- Specific fields ------------- // // - std::string msgId; + RsMessageId msgId; RsPeerId srcId; }; class RsPublicMsgInviteConfigItem : public RsMessageItem @@ -609,8 +609,8 @@ class RsMsgParentId : public RsMessageItem // ----------- Specific fields ------------- // // - std::string msgId; - std::string msgParentId; + RsMessageId msgId; + RsMessageId msgParentId; }; class RsMsgSerialiser: public RsSerialType diff --git a/libretroshare/src/services/p3msgservice.cc b/libretroshare/src/services/p3msgservice.cc index 647505012..95d54f9ba 100644 --- a/libretroshare/src/services/p3msgservice.cc +++ b/libretroshare/src/services/p3msgservice.cc @@ -116,14 +116,6 @@ RsServiceInfo p3MsgService::getServiceInfo() } -std::string p3MsgService::getNewUniqueMsgId() -{ - // MIME FIXME: This will go into MessageInfo where the ID is generated during message creation. A message will then retain it's id - std::ostringstream mid; - mid << "<" << time(NULL) << "." << RSRandom::random_u64() << "@retroshare>"; - return mid.str(); -} - int p3MsgService::tick() { pqioutput(PQL_DEBUG_BASIC, msgservicezone, @@ -160,9 +152,10 @@ int p3MsgService::status() void p3MsgService::processMsg(RsMsgItem *mi, bool incoming) { - mi -> recvTime = time(NULL); - mi -> msgId = getNewUniqueMsgId(); + MessageInfo msgInfo( mi->mimeMessage.substr( 0, mi->mimeMessage.find( "\r\n\r\n" ) ) ); + mi->msgId = msgInfo.getMessageId(); + mi -> recvTime = time(NULL); { RsStackMutex stack(mMsgMtx); /*** STACK LOCKED MTX ***/ @@ -177,13 +170,13 @@ void p3MsgService::processMsg(RsMsgItem *mi, bool incoming) if (notify) { if(mi->msgFlags & RS_MSG_FLAGS_ENCRYPTED){ -// MIME FIXME: notify->AddPopupMessage(RS_POPUP_ENCRYPTED_MSG, mi->PeerId().toStdString(), mi->subject, mi->message); + notify->AddPopupMessage(RS_POPUP_ENCRYPTED_MSG, mi->PeerId().toStdString(), msgInfo.header().subject(), "" ); } else{ -// MIME FIXME: notify->AddPopupMessage(RS_POPUP_MSG, mi->PeerId().toStdString(), mi->subject, mi->message); + notify->AddPopupMessage(RS_POPUP_MSG, mi->PeerId().toStdString(), msgInfo.header().subject(), "" ); } - notify->AddFeedItem(RS_FEED_ITEM_MESSAGE, mi->msgId, "", ""); + notify->AddFeedItem(RS_FEED_ITEM_MESSAGE, mi->msgId.toStdString(), "", ""); } } else @@ -195,7 +188,7 @@ void p3MsgService::processMsg(RsMsgItem *mi, bool incoming) RsMsgSrcId* msi = new RsMsgSrcId(); msi->msgId = mi->msgId; msi->srcId = mi->PeerId(); - mSrcIds.insert(std::pair(msi->msgId, msi)); + mSrcIds.insert(std::pair(msi->msgId, msi)); IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/ } @@ -346,11 +339,11 @@ int p3MsgService::checkOutgoingMessages() { const RsPeerId& ownId = mServiceCtrl->getOwnId(); - std::list::iterator it; - std::list toErase; + std::list::iterator it; + std::list toErase; RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/ - std::map::iterator mit; + std::map::iterator mit; for(mit = msgOutgoing.begin(); mit != msgOutgoing.end(); mit++) { if (mit->second->msgFlags & RS_MSG_FLAGS_TRASH) @@ -402,7 +395,7 @@ int p3MsgService::checkOutgoingMessages() msgOutgoing.erase(mit); } - std::map::iterator srcIt = mSrcIds.find(*it); + std::map::iterator srcIt = mSrcIds.find(*it); if (srcIt != mSrcIds.end()) { delete (srcIt->second); mSrcIds.erase(srcIt); @@ -427,11 +420,11 @@ int p3MsgService::checkOutgoingMessages() bool p3MsgService::saveList(bool& cleanup, std::list& itemList) { - std::map::iterator mit; + std::map::iterator mit; std::map::iterator mit2; - std::map::iterator mit3; - std::map::iterator lit; - std::map::iterator mit4; + std::map::iterator mit3; + std::map::iterator lit; + std::map::iterator mit4; MsgTagType stdTags; @@ -538,8 +531,8 @@ bool p3MsgService::loadList(std::list& load) std::list items; std::list::iterator it; std::map::iterator tagIt; - std::map srcIdMsgMap; - std::map::iterator srcIt; + std::map srcIdMsgMap; + std::map::iterator srcIt; bool distant_messaging_set = false ; @@ -568,16 +561,16 @@ bool p3MsgService::loadList(std::list& load) } else if(NULL != (mti = dynamic_cast(*it))) { - mMsgTags.insert(std::pair(mti->msgId, mti)); + mMsgTags.insert(std::pair(mti->msgId, mti)); } else if(NULL != (msi = dynamic_cast(*it))) { - srcIdMsgMap.insert(std::pair(msi->msgId, msi->srcId)); - mSrcIds.insert(std::pair(msi->msgId, msi)); // does not need to be kept + srcIdMsgMap.insert(std::pair(msi->msgId, msi->srcId)); + mSrcIds.insert(std::pair(msi->msgId, msi)); // does not need to be kept } else if(NULL != (msp = dynamic_cast(*it))) { - mParentId.insert(std::pair(msp->msgId, msp)); + mParentId.insert(std::pair(msp->msgId, msp)); } RsConfigKeyValueSet *vitem = NULL ; @@ -608,11 +601,6 @@ bool p3MsgService::loadList(std::list& load) { mitem = *msgIt; - /* STORE MsgID */ - if (mitem->msgId.empty()) { - mitem->msgId = getNewUniqueMsgId(); - } - RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/ srcIt = srcIdMsgMap.find(mitem->msgId); @@ -643,7 +631,7 @@ bool p3MsgService::loadList(std::list& load) /* remove missing msgId in mSrcIds */ for (srcIt = srcIdMsgMap.begin(); srcIt != srcIdMsgMap.end(); srcIt++) { - std::map::iterator it = mSrcIds.find(srcIt->first); + std::map::iterator it = mSrcIds.find(srcIt->first); if (it != mSrcIds.end()) { delete(it->second); mSrcIds.erase(it); @@ -651,7 +639,7 @@ bool p3MsgService::loadList(std::list& load) } /* remove missing msgId in mParentId */ - std::map::iterator mit = mParentId.begin(); + std::map::iterator mit = mParentId.begin(); while (mit != mParentId.end()) { if (imsg.find(mit->first) == imsg.end()) { if (msgOutgoing.find(mit->first) == msgOutgoing.end()) { @@ -687,7 +675,7 @@ void p3MsgService::loadWelcomeMsg() "Enjoy."; mi.body().set( body ); - msg -> msgId = getNewUniqueMsgId(); + msg -> msgId = mi.getMessageId(); RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/ @@ -714,7 +702,7 @@ bool p3MsgService::getMessageSummaries(std::list &msgList) RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/ - std::map::iterator mit; + std::map::iterator mit; for(mit = imsg.begin(); mit != imsg.end(); mit++) { MsgInfoSummary mis; @@ -731,9 +719,9 @@ bool p3MsgService::getMessageSummaries(std::list &msgList) return true; } -bool p3MsgService::getMessage(const std::string &msgId, MessageInfo &msg) +bool p3MsgService::getMessage(const RsMessageId &msgId, MessageInfo &msg) { - std::map::iterator mit; + std::map::iterator mit; RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/ @@ -750,7 +738,7 @@ bool p3MsgService::getMessage(const std::string &msgId, MessageInfo &msg) /* mit valid */ initRsMI(mit->second, msg); - std::map::const_iterator it = mSrcIds.find(msgId) ; + std::map::const_iterator it = mSrcIds.find(msgId) ; if(it != mSrcIds.end()) msg.rsgxsid_srcId = RsGxsId(it->second->srcId) ; @@ -768,8 +756,8 @@ void p3MsgService::getMessageCount(unsigned int *pnInbox, unsigned int *pnInboxN if (pnSentbox) *pnSentbox = 0; if (pnTrashbox) *pnTrashbox = 0; - std::map::iterator mit; - std::map *apMsg [2] = { &imsg, &msgOutgoing }; + std::map::iterator mit; + std::map *apMsg [2] = { &imsg, &msgOutgoing }; for (int i = 0; i < 2; i++) { for (mit = apMsg [i]->begin(); mit != apMsg [i]->end(); mit++) { @@ -802,10 +790,10 @@ void p3MsgService::getMessageCount(unsigned int *pnInbox, unsigned int *pnInboxN } /* remove based on the unique mid (stored in sid) */ -bool p3MsgService::removeMsgId(const std::string &msgId) +bool p3MsgService::removeMsgId(const RsMessageId &msgId) { - std::map::iterator mit; - if ( msgId.empty() ) { + std::map::iterator mit; + if ( msgId.isNull() ) { std::cerr << "p3MsgService::removeMsgId: Unknown msgId " << msgId << std::endl; return false; } @@ -833,7 +821,7 @@ bool p3MsgService::removeMsgId(const std::string &msgId) delete mi; } - std::map::iterator srcIt = mSrcIds.find(msgId); + std::map::iterator srcIt = mSrcIds.find(msgId); if (srcIt != mSrcIds.end()) { changed = true; delete (srcIt->second); @@ -845,7 +833,7 @@ bool p3MsgService::removeMsgId(const std::string &msgId) IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/ setMessageTag(msgId, 0, false); - setMsgParentId(msgId, 0); + setMsgParentId(msgId, RsMessageId()); RsServer::notify()->notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_MOD); } @@ -853,9 +841,9 @@ bool p3MsgService::removeMsgId(const std::string &msgId) return changed; } -bool p3MsgService::markMsgIdRead(const std::string &msgId, bool unreadByUser) +bool p3MsgService::markMsgIdRead(const RsMessageId &msgId, bool unreadByUser) { - std::map::iterator mit; + std::map::iterator mit; bool changed = false; { @@ -895,9 +883,9 @@ bool p3MsgService::markMsgIdRead(const std::string &msgId, bool unreadByUser) return true; } -bool p3MsgService::setMsgFlag(const std::string &msgId, uint32_t flag, uint32_t mask) +bool p3MsgService::setMsgFlag(const RsMessageId &msgId, uint32_t flag, uint32_t mask) { - std::map::iterator mit; + std::map::iterator mit; bool changed = false; { @@ -931,13 +919,13 @@ bool p3MsgService::setMsgFlag(const std::string &msgId, uint32_t flag, uint32 return true; } -bool p3MsgService::getMsgParentId(const std::string &msgId, std::string &msgParentId) +bool p3MsgService::getMsgParentId(const RsMessageId &msgId, RsMessageId &msgParentId) { msgParentId.clear(); RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/ - std::map::iterator mit = mParentId.find( msgId ); + std::map::iterator mit = mParentId.find( msgId ); if (mit == mParentId.end()) { return false; } @@ -947,9 +935,9 @@ bool p3MsgService::getMsgParentId(const std::string &msgId, std::string &msgP return true; } -bool p3MsgService::setMsgParentId(std::string msgId, const std::string & msgParentId) +bool p3MsgService::setMsgParentId(RsMessageId msgId, const RsMessageId & msgParentId) { - std::map::iterator mit; + std::map::iterator mit; bool changed = false; @@ -959,17 +947,17 @@ bool p3MsgService::setMsgParentId(std::string msgId, const std::string & msgP mit = mParentId.find(msgId); if (mit == mParentId.end()) { - if ( !msgParentId.empty() ) { + if ( !msgParentId.isNull() ) { RsMsgParentId* msp = new RsMsgParentId(); msp->PeerId (mServiceCtrl->getOwnId()); msp->msgId = msgId; msp->msgParentId = msgParentId; - mParentId.insert(std::pair(msgId, msp)); + mParentId.insert(std::pair(msgId, msp)); changed = true; } } else { - if ( !msgParentId.empty() ) { + if ( !msgParentId.isNull() ) { if (mit->second->msgParentId != msgParentId) { mit->second->msgParentId = msgParentId; changed = true; @@ -1000,8 +988,6 @@ int p3MsgService::sendMessage(RsMsgItem *item) pqioutput(PQL_DEBUG_BASIC, msgservicezone, "p3MsgService::sendMessage()"); - item -> msgId = getNewUniqueMsgId(); /* grabs Mtx as well */ - { RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/ @@ -1015,7 +1001,7 @@ int p3MsgService::sendMessage(RsMsgItem *item) RsMsgSrcId* msi = new RsMsgSrcId(); msi->msgId = item->msgId; msi->srcId = item->PeerId(); - mSrcIds.insert(std::pair(msi->msgId, msi)); + mSrcIds.insert(std::pair(msi->msgId, msi)); } } @@ -1095,9 +1081,6 @@ bool p3MsgService::MessageSend(MessageInfo &info) /* use processMsg to get the new msgId */ processMsg(msg, false); - - // return new message id - info.header().messageid() = msg->msgId; } return true; @@ -1141,21 +1124,17 @@ bool p3MsgService::SystemMessage(const std::string &title, const std::string &me return true; } -bool p3MsgService::MessageToDraft(MessageInfo &info, const std::string &msgParentId) +bool p3MsgService::MessageToDraft(MessageInfo &info, const RsMessageId &msgParentId) { RsMsgItem *msg = initMIRsMsg(info, mServiceCtrl->getOwnId()); if (msg) { - std::string msgId; + RsMessageId msgId; if ( !info.header().messageid().str().empty() ) { - msgId = info.header().messageid().str(); + msgId = info.getMessageId(); } - if ( !msgId.empty() ) { msg->msgId = msgId; - } else { - msg->msgId = getNewUniqueMsgId(); /* grabs Mtx as well */ - } { RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/ @@ -1163,9 +1142,9 @@ bool p3MsgService::MessageToDraft(MessageInfo &info, const std::string &msgParen /* add pending flag */ msg->msgFlags |= (RS_MSG_OUTGOING | RS_MSG_FLAGS_DRAFT); - if ( !msgId.empty() ) { + if ( !msgId.isNull() ) { // remove existing message - std::map::iterator mit; + std::map::iterator mit; mit = imsg.find(msgId); if (mit != imsg.end()) { RsMsgItem *mi = mit->second; @@ -1175,9 +1154,6 @@ bool p3MsgService::MessageToDraft(MessageInfo &info, const std::string &msgParen } /* STORE MsgID */ imsg[msg->msgId] = msg; - - // return new message id - info.header().messageid( msg->msgId ); } setMsgParentId( msg->msgId, msgParentId ); @@ -1282,7 +1258,7 @@ bool p3MsgService::removeMessageTagType(uint32_t tagId) } /* search for messages with this tag type */ - std::map::iterator mit1; + std::map::iterator mit1; for (mit1 = mMsgTags.begin(); mit1 != mMsgTags.end(); ) { RsMsgTags* tag = mit1->second; @@ -1315,16 +1291,16 @@ bool p3MsgService::removeMessageTagType(uint32_t tagId) return true; } -bool p3MsgService::getMessageTag(const std::string &msgId, MsgTagInfo& info) +bool p3MsgService::getMessageTag(const RsMessageId &msgId, MsgTagInfo& info) { RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/ - if ( msgId.empty() ) { + if ( msgId.isNull() ) { std::cerr << "p3MsgService::MessageGetMsgTag: Unknown msgId " << msgId << std::endl; return false; } - std::map::iterator mit; + std::map::iterator mit; if(mMsgTags.end() != ( mit = mMsgTags.find( msgId ))) { info.msgId = mit->second->msgId; @@ -1337,9 +1313,9 @@ bool p3MsgService::getMessageTag(const std::string &msgId, MsgTagInfo& info) } /* set == false && tagId == 0 --> remove all */ -bool p3MsgService::setMessageTag(const std::string &msgId, uint32_t tagId, bool set) +bool p3MsgService::setMessageTag(const RsMessageId &msgId, uint32_t tagId, bool set) { - if ( msgId.empty() ) { + if ( msgId.isNull() ) { std::cerr << "p3MsgService::MessageSetMsgTag: Unknown msgId " << msgId << std::endl; return false; } @@ -1356,7 +1332,7 @@ bool p3MsgService::setMessageTag(const std::string &msgId, uint32_t tagId, bool { RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/ - std::map::iterator mit; + std::map::iterator mit; mit = mMsgTags.find( msgId ); if (mit == mMsgTags.end()) { @@ -1368,7 +1344,7 @@ bool p3MsgService::setMessageTag(const std::string &msgId, uint32_t tagId, bool tag->msgId = msgId; tag->tagIds.push_back(tagId); - mMsgTags.insert(std::pair(tag->msgId, tag)); + mMsgTags.insert(std::pair(tag->msgId, tag)); nNotifyType = NOTIFY_TYPE_ADD; } @@ -1438,9 +1414,9 @@ bool p3MsgService::resetMessageStandardTagTypes(MsgTagType& tags) } /* move message to trash based on the unique mid */ -bool p3MsgService::MessageToTrash(const std::string &msgId, bool bTrash) +bool p3MsgService::MessageToTrash(const RsMessageId &msgId, bool bTrash) { - std::map::iterator mit; + std::map::iterator mit; bool bChanged = false; bool bFound = false; @@ -1610,15 +1586,17 @@ void p3MsgService::initRsMIS(RsMsgItem *msg, MsgInfoSummary &mis) mis.ts = msg->sendTime; } -void p3MsgService::initMIRsMsg(RsMsgItem *msg, MessageInfo info) +void p3MsgService::initMIRsMsg(RsMsgItem *msg, MessageInfo & info) { msg -> msgFlags = 0; - msg -> msgId.clear(); msg -> sendTime = time(NULL); msg -> recvTime = 0; + msg -> msgId = info.getMessageId(); + /* We don't fill in bcc (unless to ourselves) */ // MIME FIXME: Do not delete BCC fields for SMTP mails to a gateway + // MIME FIXME: the following used to clear BCC from a copy. Now it is the original. BCC needs to be treated outside of the MimeEntity tree if (msg->PeerId() == mServiceCtrl->getOwnId()){ info.header().bcc().clear(); } @@ -1632,7 +1610,7 @@ void p3MsgService::initMIRsMsg(RsMsgItem *msg, MessageInfo info) if (info.msgflags & RS_MSG_FRIEND_RECOMMENDATION) msg->msgFlags |= RS_MSG_FLAGS_FRIEND_RECOMMENDATION; } -RsMsgItem *p3MsgService::initMIRsMsg( const MessageInfo& info, const RsGxsId& to) +RsMsgItem *p3MsgService::initMIRsMsg( MessageInfo& info, const RsGxsId& to) { RsMsgItem *msg = new RsMsgItem(); @@ -1657,7 +1635,7 @@ RsMsgItem *p3MsgService::initMIRsMsg( const MessageInfo& info, const RsGxsId& to return msg ; } -RsMsgItem *p3MsgService::initMIRsMsg( const MessageInfo &info, const RsPeerId& to) +RsMsgItem *p3MsgService::initMIRsMsg( MessageInfo &info, const RsPeerId& to) { RsMsgItem *msg = new RsMsgItem(); @@ -1830,7 +1808,7 @@ std::string printNumber(uint32_t n,bool hex) os << n ; return os.str() ; } -bool p3MsgService::decryptMessage(const std::string& msgId) +bool p3MsgService::decryptMessage(const RsMessageId& msgId) { uint8_t *decrypted_data = NULL; char *encrypted_data = NULL; @@ -1846,7 +1824,7 @@ bool p3MsgService::decryptMessage(const std::string& msgId) { RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/ - std::map::iterator mit = imsg.find(msgId); + std::map::iterator mit = imsg.find(msgId); if(mit == imsg.end()) { @@ -2046,7 +2024,7 @@ bool p3MsgService::decryptMessage(const std::string& msgId) msgi.msgFlags &= ~RS_MSG_FLAGS_SIGNATURE_CHECKS ; // just in case. } - std::map::iterator it = mSrcIds.find(msgi.msgId) ; + std::map::iterator it = mSrcIds.find(msgi.msgId) ; if(it == mSrcIds.end()) { @@ -2056,7 +2034,7 @@ bool p3MsgService::decryptMessage(const std::string& msgId) msi->msgId = msgi.msgId; msi->srcId = RsPeerId(senders_id) ; - mSrcIds.insert(std::pair(msi->msgId, msi)); + mSrcIds.insert(std::pair(msi->msgId, msi)); } else { @@ -2169,7 +2147,7 @@ void p3MsgService::acknowledgeDataReceived(const GRouterMsgPropagationId& id) #ifdef DEBUG_DISTANT_MSG std::cerr << "p3MsgService::acknowledgeDataReceived(): acknowledging data received for msg propagation id " << id << std::endl; #endif - std::map::iterator it = _ongoing_messages.find(id) ; + std::map::iterator it = _ongoing_messages.find(id) ; if(it == _ongoing_messages.end()) { @@ -2177,11 +2155,11 @@ void p3MsgService::acknowledgeDataReceived(const GRouterMsgPropagationId& id) return ; } - std::string msg_id = it->second ; + RsMessageId msg_id = it->second ; // we should now remove the item from the msgOutgoing list. - std::map::iterator it2 = msgOutgoing.find(msg_id) ; + std::map::iterator it2 = msgOutgoing.find(msg_id) ; if(it2 == msgOutgoing.end()) { @@ -2238,6 +2216,22 @@ void p3MsgService::sendPrivateMsgItem(RsMsgItem *msgitem) // We assume that there will never be a "retroshare" TLD static const char * RSPEERID_POSTFIX = "rspeerid.retroshare"; static const char * RSGXSID_POSTFIX = "rsgxsid.retroshare"; +static const char * RSMSGID_POSTFIX = "retroshare"; + +MessageInfo::MessageInfo() +{ + std::ostringstream mid; + mid << "<" << time(NULL) << "." << RSRandom::random_u64() << "@" << RSMSGID_POSTFIX << ">"; + header().messageid() = mid.str(); +} + +RsMessageId MessageInfo::getMessageId() +{ + std::string id = header().messageid().str(); + return RsDirUtil::sha1sum( (unsigned char*)id.c_str(), id.length() ); +} + + void MessageInfo::setMessage( const std::string & msg ) { diff --git a/libretroshare/src/services/p3msgservice.h b/libretroshare/src/services/p3msgservice.h index c945133ec..f0c73181f 100644 --- a/libretroshare/src/services/p3msgservice.h +++ b/libretroshare/src/services/p3msgservice.h @@ -62,29 +62,29 @@ class p3MsgService: public p3Service, public p3Config, public pqiServiceMonitor, /* External Interface */ bool getMessageSummaries(std::list &msgList); - bool getMessage(const std::string &mid, MessageInfo &msg); + bool getMessage(const RsMessageId &mid, MessageInfo &msg); void getMessageCount(unsigned int *pnInbox, unsigned int *pnInboxNew, unsigned int *pnOutbox, unsigned int *pnDraftbox, unsigned int *pnSentbox, unsigned int *pnTrashbox); - bool decryptMessage(const std::string& mid) ; - bool removeMsgId(const std::string &mid); - bool markMsgIdRead(const std::string &mid, bool bUnreadByUser); - bool setMsgFlag(const std::string &mid, uint32_t flag, uint32_t mask); - bool getMsgParentId(const std::string &msgId, std::string &msgParentId); + bool decryptMessage(const RsMessageId &mid) ; + bool removeMsgId(const RsMessageId &mid); + bool markMsgIdRead(const RsMessageId &mid, bool bUnreadByUser); + bool setMsgFlag(const RsMessageId &mid, uint32_t flag, uint32_t mask); + bool getMsgParentId(const RsMessageId &msgId, RsMessageId &msgParentId); // msgParentId == 0 --> remove - bool setMsgParentId(std::string msgId, const std::string &msgParentId); + bool setMsgParentId(RsMessageId msgId, const RsMessageId &msgParentId); bool MessageSend(MessageInfo &info); bool SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag); - bool MessageToDraft(MessageInfo &info, const std::string &msgParentId); - bool MessageToTrash(const std::string &mid, bool bTrash); + bool MessageToDraft(MessageInfo &info, const RsMessageId &msgParentId); + bool MessageToTrash(const RsMessageId &mid, bool bTrash); bool getMessageTagTypes(MsgTagType& tags); bool setMessageTagType(uint32_t tagId, std::string& text, uint32_t rgb_color); bool removeMessageTagType(uint32_t tagId); - bool getMessageTag(const std::string &msgId, MsgTagInfo& info); + bool getMessageTag(const RsMessageId &msgId, MsgTagInfo& info); /* set == false && tagId == 0 --> remove all */ - bool setMessageTag(const std::string &msgId, uint32_t tagId, bool set); + bool setMessageTag(const RsMessageId &msgId, uint32_t tagId, bool set); bool resetMessageStandardTagTypes(MsgTagType& tags); @@ -132,7 +132,7 @@ class p3MsgService: public p3Service, public p3Config, public pqiServiceMonitor, // This contains the ongoing tunnel handling contacts. // The map is indexed by the hash // - std::map _ongoing_messages ; + std::map _ongoing_messages ; // Overloaded from GRouterClientService @@ -149,7 +149,6 @@ class p3MsgService: public p3Service, public p3Config, public pqiServiceMonitor, void handleIncomingItem(RsMsgItem *) ; - std::string getNewUniqueMsgId(); int sendMessage(RsMsgItem *item); void checkSizeAndSendMessage(RsMsgItem *msg); @@ -160,9 +159,9 @@ class p3MsgService: public p3Service, public p3Config, public pqiServiceMonitor, void initRsMI(RsMsgItem *msg, MessageInfo &mi); void initRsMIS(RsMsgItem *msg, MsgInfoSummary &mis); - RsMsgItem *initMIRsMsg(const MessageInfo &info, const RsPeerId& to); - RsMsgItem *initMIRsMsg(const MessageInfo &info, const RsGxsId& to); - void initMIRsMsg(RsMsgItem *item, MessageInfo info) ; + RsMsgItem *initMIRsMsg(MessageInfo &info, const RsPeerId& to); + RsMsgItem *initMIRsMsg(MessageInfo &info, const RsGxsId& to); + void initMIRsMsg(RsMsgItem *item, MessageInfo &info) ; void initStandardTagTypes(); @@ -176,24 +175,24 @@ class p3MsgService: public p3Service, public p3Config, public pqiServiceMonitor, RsMsgSerialiser *_serialiser ; /* stored list of messages */ - std::map imsg; + std::map imsg; /* ones that haven't made it out yet! */ - std::map msgOutgoing; + std::map msgOutgoing; std::map _pendingPartialMessages ; /* maps for tags types and msg tags */ std::map mTags; - std::map mMsgTags; + std::map mMsgTags; uint32_t mMsgUniqueId; // used delete msgSrcIds after config save - std::map< std::string, RsMsgSrcId*> mSrcIds; + std::map mSrcIds; // save the parent of the messages in draft for replied and forwarded - std::map mParentId; + std::map mParentId; std::string config_dir; diff --git a/retroshare-gui/src/gui/MessagesDialog.cpp b/retroshare-gui/src/gui/MessagesDialog.cpp index 165734a5a..8df275cc8 100644 --- a/retroshare-gui/src/gui/MessagesDialog.cpp +++ b/retroshare-gui/src/gui/MessagesDialog.cpp @@ -151,7 +151,7 @@ MessagesDialog::MessagesDialog(QWidget *parent) listMode = LIST_NOTHING; - mCurrMsgId = ""; + mCurrMsgId = RsMessageId(); // Set the QStandardItemModel MessagesModel = new QStandardItemModel(0, COLUMN_COUNT); @@ -531,8 +531,8 @@ bool MessagesDialog::hasMessageStar(int nRow) void MessagesDialog::messageslistWidgetCustomPopupMenu( QPoint /*point*/ ) { - std::string cid; - std::string mid; + RsPeerId cid; + RsMessageId mid; MessageInfo msgInfo; if (getCurrentMsg(cid, mid)) { @@ -659,8 +659,8 @@ void MessagesDialog::newmessage() void MessagesDialog::openAsWindow() { - std::string cid; - std::string mid; + RsPeerId cid; + RsMessageId mid; if(!getCurrentMsg(cid, mid)) return ; @@ -677,8 +677,8 @@ void MessagesDialog::openAsWindow() void MessagesDialog::openAsTab() { - std::string cid; - std::string mid; + RsPeerId cid; + RsMessageId mid; if(!getCurrentMsg(cid, mid)) return ; @@ -696,8 +696,8 @@ void MessagesDialog::openAsTab() void MessagesDialog::editmessage() { - std::string cid; - std::string mid; + RsPeerId cid; + RsMessageId mid; if(!getCurrentMsg(cid, mid)) return ; @@ -1001,7 +1001,7 @@ void MessagesDialog::insertMessages() for (nRow = 0; nRow < nRowCount; ) { std::string msgIdFromRow = MessagesModel->item(nRow, COLUMN_DATA)->data(ROLE_MSGID).toString().toStdString(); for(it = msgToShow.begin(); it != msgToShow.end(); it++) { - if (it->msgId == msgIdFromRow) { + if (it->msgId == RsMessageId(msgIdFromRow)) { break; } } @@ -1040,7 +1040,7 @@ void MessagesDialog::insertMessages() // search exisisting items nRowCount = MessagesModel->rowCount(); for (nRow = 0; nRow < nRowCount; nRow++) { - if (it->msgId == MessagesModel->item(nRow, COLUMN_DATA)->data(ROLE_MSGID).toString().toStdString()) { + if (it->msgId == RsMessageId( MessagesModel->item(nRow, COLUMN_DATA)->data(ROLE_MSGID).toString().toStdString())) { break; } } @@ -1160,7 +1160,7 @@ void MessagesDialog::insertMessages() item[COLUMN_SUBJECT]->setData(text + dateString, ROLE_SORT); // internal data - QString msgId = QString::fromStdString(it->msgId); + QString msgId = QString::fromStdString(it->msgId.toStdString() ); item[COLUMN_DATA]->setData(QString::fromStdString(it->srcId.toStdString()), ROLE_SRCID); item[COLUMN_DATA]->setData(msgId, ROLE_MSGID); item[COLUMN_DATA]->setData(it->msgflags, ROLE_MSGFLAGS); @@ -1210,27 +1210,28 @@ void MessagesDialog::insertMessages() item[i]->setForeground(brush); } - // No of Files. - { -// MIME FIXME: item[COLUMN_ATTACHEMENTS] -> setText(QString::number(it -> count)); - item[COLUMN_ATTACHEMENTS] -> setData(item[COLUMN_ATTACHEMENTS]->text() + dateString, ROLE_SORT); - item[COLUMN_ATTACHEMENTS] -> setTextAlignment(Qt::AlignHCenter); - } - + unsigned int filecount = 0; if (filterColumn == COLUMN_CONTENT) { // need content for filter if (gotInfo || rsMsgs->getMessage(it->msgId, msgInfo)) { gotInfo = true; QTextDocument doc; - mimetic::MimeEntityList meList = msgInfo.body().parts(); - std::string body; - for( mimetic::MimeEntityList::const_iterator it = meList.begin(); it != meList.end(); it++ ){ + if( msgInfo.header().contentType().str() == "multipart/mixed" ){ + mimetic::MimeEntityList & parts = msgInfo.body().parts(); + filecount = parts.size() - 1; // first part will be the text body + for( mimetic::MimeEntityList::const_iterator it = parts.begin(); it != parts.end(); it++ ){ mimetic::MimeEntity * part = *it; if( part->header().contentType().type() == "text" ){ - body = part->body().data(); + std::string body = part->body().data(); + doc.setHtml( QString::fromUtf8( body.c_str() ) ); + break; } } + } + else if( msgInfo.header().contentType().type() == "text" ){ + std::string body = msgInfo.body().data(); doc.setHtml( QString::fromUtf8( body.c_str() ) ); + } item[COLUMN_CONTENT]->setText(doc.toPlainText().replace(QString("\n"), QString(" "))); } else { std::cerr << "MessagesDialog::insertMsgTxtAndFiles() Couldn't find Msg" << std::endl; @@ -1238,6 +1239,13 @@ void MessagesDialog::insertMessages() } } + // No of Files. + { + item[COLUMN_ATTACHEMENTS] -> setText(QString::number( filecount )); + item[COLUMN_ATTACHEMENTS] -> setData(item[COLUMN_ATTACHEMENTS]->text() + dateString, ROLE_SORT); + item[COLUMN_ATTACHEMENTS] -> setTextAlignment(Qt::AlignHCenter); + } + if(it->msgflags & RS_MSG_ENCRYPTED) { item[COLUMN_SIGNATURE]->setIcon(QIcon(":/images/blue_lock.png")) ; @@ -1339,8 +1347,8 @@ void MessagesDialog::doubleClicked(const QModelIndex &index) /* activate row */ clicked (index); - std::string cid; - std::string mid; + RsPeerId cid; + RsMessageId mid; if(!getCurrentMsg(cid, mid)) return ; @@ -1386,7 +1394,7 @@ void MessagesDialog::setMsgAsReadUnread(const QList &Rows, bool read) std::string mid = item[COLUMN_DATA]->data(ROLE_MSGID).toString().toStdString(); - if (rsMsgs->MessageRead(mid, !read)) { + if (rsMsgs->MessageRead(RsMessageId(mid), !read)) { int msgFlag = item[COLUMN_DATA]->data(ROLE_MSGFLAGS).toInt(); msgFlag &= ~RS_MSG_NEW; @@ -1444,7 +1452,7 @@ void MessagesDialog::setMsgStar(const QList &Rows, bool star) std::string mid = item[COLUMN_DATA]->data(ROLE_MSGID).toString().toStdString(); - if (rsMsgs->MessageStar(mid, star)) { + if (rsMsgs->MessageStar(RsMessageId(mid), star)) { int msgFlag = item[COLUMN_DATA]->data(ROLE_MSGFLAGS).toInt(); msgFlag &= ~RS_MSG_STAR; @@ -1470,8 +1478,8 @@ void MessagesDialog::insertMsgTxtAndFiles(QModelIndex Index, bool bSetToRead) std::cerr << "MessagesDialog::insertMsgTxtAndFiles()" << std::endl; /* get its Ids */ - std::string cid; - std::string mid; + RsMessageId cid; + RsMessageId mid; QModelIndex currentIndex = proxyModel->mapToSource(Index); if (currentIndex.isValid() == false) { @@ -1488,7 +1496,7 @@ void MessagesDialog::insertMsgTxtAndFiles(QModelIndex Index, bool bSetToRead) updateInterface(); return; } - mid = item->data(ROLE_MSGID).toString().toStdString(); + mid = RsMessageId(item->data(ROLE_MSGID).toString().toStdString()); int nCount = getSelectedMsgCount (NULL, NULL, NULL, NULL); if (nCount == 1) { @@ -1550,12 +1558,12 @@ void MessagesDialog::decryptSelectedMsg() // Force refill mCurrMsgId.clear(); - msgWidget->fill(""); + msgWidget->fill(RsMessageId()); insertMsgTxtAndFiles(ui.messagestreeView->currentIndex()); } -bool MessagesDialog::getCurrentMsg(std::string &cid, std::string &mid) +bool MessagesDialog::getCurrentMsg(RsPeerId &cid, RsMessageId &mid) { QModelIndex currentIndex = ui.messagestreeView->currentIndex(); currentIndex = proxyModel->mapToSource(currentIndex); @@ -1583,8 +1591,8 @@ bool MessagesDialog::getCurrentMsg(std::string &cid, std::string &mid) if (item == NULL) { return false; } - cid = item->data(ROLE_SRCID).toString().toStdString(); - mid = item->data(ROLE_MSGID).toString().toStdString(); + cid = RsPeerId(item->data(ROLE_SRCID).toString().toStdString()); + mid = RsMessageId(item->data(ROLE_MSGID).toString().toStdString()); return true; } @@ -1623,9 +1631,9 @@ void MessagesDialog::removemessage() // closeTab(mid.toStdString()); if (bDelete) { - rsMsgs->MessageDelete(mid.toStdString()); + rsMsgs->MessageDelete(RsMessageId(mid.toStdString())); } else { - rsMsgs->MessageToTrash(mid.toStdString(), true); + rsMsgs->MessageToTrash(RsMessageId(mid.toStdString()), true); } } } @@ -1641,7 +1649,7 @@ void MessagesDialog::undeletemessage() getSelectedMsgCount (&Rows, NULL, NULL, NULL); for (int nRow = 0; nRow < Rows.size(); nRow++) { QString mid = MessagesModel->item (Rows [nRow], COLUMN_DATA)->data(ROLE_MSGID).toString(); - rsMsgs->MessageToTrash(mid.toStdString(), false); + rsMsgs->MessageToTrash(RsMessageId(mid.toStdString()), false); } // LockUpdate -> insertMessages(); @@ -1911,7 +1919,7 @@ void MessagesDialog::tagAboutToShow() QStandardItem* item = MessagesModel->item(rows [0], COLUMN_DATA); std::string msgId = item->data(ROLE_MSGID).toString().toStdString(); - rsMsgs->getMessageTag(msgId, tagInfo); + rsMsgs->getMessageTag(RsMessageId(msgId), tagInfo); } menu->activateActions(tagInfo.tagIds); @@ -1927,7 +1935,7 @@ void MessagesDialog::tagRemoveAll() QStandardItem* item = MessagesModel->item(rows [row], COLUMN_DATA); std::string msgId = item->data(ROLE_MSGID).toString().toStdString(); - rsMsgs->setMessageTag(msgId, 0, false); + rsMsgs->setMessageTag(RsMessageId(msgId), 0, false); Lock.setUpdate(true); } @@ -1948,7 +1956,7 @@ void MessagesDialog::tagSet(int tagId, bool set) QStandardItem* item = MessagesModel->item(rows [row], COLUMN_DATA); std::string msgId = item->data(ROLE_MSGID).toString().toStdString(); - if (rsMsgs->setMessageTag(msgId, tagId, set)) { + if (rsMsgs->setMessageTag(RsMessageId(msgId), tagId, set)) { Lock.setUpdate(true); } } @@ -1992,7 +2000,7 @@ void MessagesDialog::tabCloseRequested(int tab) } } -void MessagesDialog::closeTab(const std::string &msgId) +void MessagesDialog::closeTab(const RsMessageId &msgId) { QList msgWidgets; @@ -2063,7 +2071,7 @@ void MessagesDialog::updateInterface() count = getSelectedMsgCount(NULL, NULL, NULL, NULL); } else { MessageWidget *msg = dynamic_cast(ui.tabWidget->widget(tab)); - if (msg && msg->msgId().empty() == false) { + if (msg && msg->msgId().isNull() == false) { count = 1; } } diff --git a/retroshare-gui/src/gui/MessagesDialog.h b/retroshare-gui/src/gui/MessagesDialog.h index ea1b44057..40d1dc136 100644 --- a/retroshare-gui/src/gui/MessagesDialog.h +++ b/retroshare-gui/src/gui/MessagesDialog.h @@ -26,6 +26,7 @@ #include "mainpage.h" #include "ui_MessagesDialog.h" +#include #define IMAGE_MESSAGES ":/images/evolution.png" @@ -127,7 +128,7 @@ private: void updateMessageSummaryList(); void insertMsgTxtAndFiles(QModelIndex index = QModelIndex(), bool bSetToRead = true); - bool getCurrentMsg(std::string &cid, std::string &mid); + bool getCurrentMsg(RsPeerId &cid, RsMessageId &mid); void setMsgAsReadUnread(const QList &Rows, bool read); void setMsgStar(const QList &Rows, bool mark); @@ -140,7 +141,7 @@ private: void setToolbarButtonStyle(Qt::ToolButtonStyle style); void fillQuickView(); - void closeTab(const std::string &msgId); + void closeTab(const RsMessageId &msgId); bool inProcessSettings; bool inChange; @@ -148,7 +149,7 @@ private: enum { LIST_NOTHING, LIST_BOX, LIST_QUICKVIEW } listMode; - std::string mCurrMsgId; + RsMessageId mCurrMsgId; // timer and index for showing message QTimer *timer; diff --git a/retroshare-gui/src/gui/NewsFeed.cpp b/retroshare-gui/src/gui/NewsFeed.cpp index cebe1f54b..0a9f45210 100644 --- a/retroshare-gui/src/gui/NewsFeed.cpp +++ b/retroshare-gui/src/gui/NewsFeed.cpp @@ -417,7 +417,7 @@ void NewsFeed::testFeeds(uint notifyFlags) for (msgIt = msgList.begin(); msgIt != msgList.end(); ++msgIt) { if (fi.mId1.empty()) { /* store first message */ - fi.mId1 = msgIt->msgId; + fi.mId1 = msgIt->msgId.toStdString(); } if (msgIt->msgflags & RS_MSG_TRASH) { @@ -426,7 +426,7 @@ void NewsFeed::testFeeds(uint notifyFlags) if ((msgIt->msgflags & RS_MSG_BOXMASK) == RS_MSG_INBOX) { /* take message from inbox */ - fi.mId1 = msgIt->msgId; + fi.mId1 = msgIt->msgId.toStdString(); break; } } diff --git a/retroshare-gui/src/gui/feeds/MsgItem.h b/retroshare-gui/src/gui/feeds/MsgItem.h index cb61991e7..03bee1465 100644 --- a/retroshare-gui/src/gui/feeds/MsgItem.h +++ b/retroshare-gui/src/gui/feeds/MsgItem.h @@ -55,7 +55,7 @@ private: uint32_t mFeedId; RsPeerId mPeerId; - std::string mMsgId; + RsMessageId mMsgId; bool mIsHome; diff --git a/retroshare-gui/src/gui/msgs/MessageComposer.cpp b/retroshare-gui/src/gui/msgs/MessageComposer.cpp index 8d014b00b..bc64c1c2a 100644 --- a/retroshare-gui/src/gui/msgs/MessageComposer.cpp +++ b/retroshare-gui/src/gui/msgs/MessageComposer.cpp @@ -57,6 +57,7 @@ #include "textformat.h" #include "util/misc.h" #include "util/DateTime.h" +#include "util/radix64.h" #include "TagsMenu.h" #include "gui/common/TagDefs.h" #include "gui/connect/ConfCertDialog.h" @@ -866,16 +867,16 @@ static void calculateGroupsOfSslIds(const std::list &existingGroupI } } -MessageComposer *MessageComposer::newMsg(const std::string &msgId /* = ""*/) +MessageComposer *MessageComposer::newMsg(const RsMessageId &msgId) { MessageComposer *msgComposer = new MessageComposer(); msgComposer->addEmptyRecipient(); - if (msgId.empty() == false) { + if (msgId.isNull() == false) { // fill existing message MessageInfo msgInfo; - if (!rsMsgs->getMessage(msgId, msgInfo)) { + if (!rsMsgs->getMessage(RsMessageId(msgId), msgInfo)) { std::cerr << "MessageComposer::newMsg() Couldn't find Msg" << std::endl; delete msgComposer; return NULL; @@ -972,7 +973,7 @@ MessageComposer *MessageComposer::newMsg(const std::string &msgId /* = ""*/) } MsgTagInfo tagInfo; - rsMsgs->getMessageTag(msgId, tagInfo); + rsMsgs->getMessageTag(RsMessageId(msgId), tagInfo); msgComposer->m_tagIds = tagInfo.tagIds; msgComposer->showTagLabels(); @@ -1093,7 +1094,7 @@ void MessageComposer::setQuotedMsg(const QString &msg, const QString &header) ui.msgText->setFocus( Qt::OtherFocusReason ); } -MessageComposer *MessageComposer::replyMsg(const std::string &msgId, bool all) +MessageComposer *MessageComposer::replyMsg(const RsMessageId &msgId, bool all) { MessageInfo msgInfo; if (!rsMsgs->getMessage(msgId, msgInfo)) { @@ -1156,7 +1157,7 @@ MessageComposer *MessageComposer::replyMsg(const std::string &msgId, bool all) return msgComposer; } -MessageComposer *MessageComposer::forwardMsg(const std::string &msgId) +MessageComposer *MessageComposer::forwardMsg(const RsMessageId &msgId) { MessageInfo msgInfo; if (!rsMsgs->getMessage(msgId, msgInfo)) { @@ -1252,10 +1253,6 @@ bool MessageComposer::sendMessage_internal(bool bDraftbox) // needed to send system flags with reply mi.msgflags = msgFlags; - QString text; - RsHtml::optimizeHtml(ui.msgText, text); - mi.body().assign( text.toUtf8().constData() ); - /* check for existing title */ if (bDraftbox == false && mi.header().subject().empty()) { if (QMessageBox::warning(this, tr("RetroShare"), tr("Do you want to send the message without a subject ?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::No) { @@ -1265,18 +1262,48 @@ bool MessageComposer::sendMessage_internal(bool bDraftbox) } int filesCount = ui.msgFileList->topLevelItemCount(); + if( filesCount == 0){ + mi.header().contentType().set("text/plain"); + mi.body().assign( ui.msgText->toPlainText().toStdString() ); +// QString text; +// RsHtml::optimizeHtml(ui.msgText, text); +// mi.body().assign( text.toUtf8().constData() ); + } + else{ + mi.header().contentType().set("multipart/mixed"); + mimetic::MimeEntity * textBody = new mimetic::MimeEntity; + textBody->header().contentType().set( "text/plain" ); + textBody->body().assign( ui.msgText->toPlainText().toStdString() ); + mimetic::MimeEntityList & parts = mi.body().parts(); + parts.push_back( textBody ); + for (int i = 0; i < filesCount; i++) { QTreeWidgetItem *item = ui.msgFileList->topLevelItem(i); if (item->checkState(COLUMN_FILE_CHECKED)) { RsFileHash hash ( item->text(COLUMN_FILE_HASH).toStdString() ); for(std::list::iterator it = _recList.begin(); it != _recList.end(); it++) { - if (it->hash == hash) { -// MIME FIXME: mi.files.push_back(*it); + FileInfo fInfo = *it; + if ( fInfo.hash == hash) { + std::ifstream attachmentStream( fInfo.path.c_str() ); + if( !attachmentStream.good()){ + QMessageBox::warning(this, tr("RetroShare"), tr("Cannot open file to attach: ") + QString::fromStdString( fInfo.fname ) ); + return false; + } + std::string attachmentString((std::istreambuf_iterator(attachmentStream)), std::istreambuf_iterator()); + mimetic::MimeEntity * attachment = new mimetic::MimeEntity; + std::string contentType = std::string( "application/octet-stream; name=" ) + fInfo.fname; + attachment->header().contentType().set( contentType ); + attachment->header().contentTransferEncoding().set( "base64" ); + std::string base64Attachment; + Radix64::encode( attachmentString.c_str(), attachmentString.length(), base64Attachment ); + attachment->body().assign( base64Attachment ); + parts.push_back( attachment ); break; } } } } + } /* get the ids from the send list */ std::list peers; @@ -1371,12 +1398,10 @@ bool MessageComposer::sendMessage_internal(bool bDraftbox) if (bDraftbox) { - mi.header().messageid() = m_sDraftMsgId; - rsMsgs->MessageToDraft(mi, m_msgParentId); // use new message id - m_sDraftMsgId = mi.header().messageid().str(); + m_sDraftMsgId = mi.getMessageId(); switch (m_msgType) { case NORMAL: @@ -1405,29 +1430,29 @@ bool MessageComposer::sendMessage_internal(bool bDraftbox) return false; } - if (m_msgParentId.empty() == false) { + if (m_msgParentId.isNull() == false) { switch (m_msgType) { case NORMAL: break; case REPLY: - rsMsgs->MessageReplied(m_msgParentId, true); + rsMsgs->MessageReplied(RsMessageId(m_msgParentId), true); break; case FORWARD: - rsMsgs->MessageForwarded(m_msgParentId, true); + rsMsgs->MessageForwarded(RsMessageId(m_msgParentId), true); break; } } } - if (mi.header().messageid().str().empty() == false) { + if (mi.getMessageId().isNull() == false) { MsgTagInfo tagInfo; - rsMsgs->getMessageTag(mi.header().messageid().str(), tagInfo); + rsMsgs->getMessageTag(mi.getMessageId(), tagInfo); /* insert new tags */ std::list::iterator tag; for (tag = m_tagIds.begin(); tag != m_tagIds.end(); tag++) { if (std::find(tagInfo.tagIds.begin(), tagInfo.tagIds.end(), *tag) == tagInfo.tagIds.end()) { - rsMsgs->setMessageTag(mi.header().messageid().str(), *tag, true); + rsMsgs->setMessageTag(mi.getMessageId(), *tag, true); } else { tagInfo.tagIds.remove(*tag); } @@ -1435,7 +1460,7 @@ bool MessageComposer::sendMessage_internal(bool bDraftbox) /* remove deleted tags */ for (tag = tagInfo.tagIds.begin(); tag != tagInfo.tagIds.end(); tag++) { - rsMsgs->setMessageTag(mi.header().messageid().str(), *tag, false); + rsMsgs->setMessageTag(mi.getMessageId(), *tag, false); } } ui.msgText->document()->setModified(false); @@ -2404,6 +2429,7 @@ void MessageComposer::fileHashingFinished(QList hashedFiles) QList::iterator it; for (it = hashedFiles.begin(); it != hashedFiles.end(); ++it) { FileInfo info; + info.path = it->filepath.toUtf8().constData(); info.fname = it->filename.toUtf8().constData(); info.hash = it->hash; info.size = it->size; diff --git a/retroshare-gui/src/gui/msgs/MessageComposer.h b/retroshare-gui/src/gui/msgs/MessageComposer.h index 0ed6f52f3..8a534bc52 100644 --- a/retroshare-gui/src/gui/msgs/MessageComposer.h +++ b/retroshare-gui/src/gui/msgs/MessageComposer.h @@ -58,9 +58,9 @@ public: static void recommendFriend(const std::list &sslIds, const RsPeerId &to = RsPeerId(), const QString &msg = "", bool autoSend = false); static void sendConnectAttemptMsg(const RsPgpId &gpgId, const RsPeerId &sslId, const QString &sslName); - static MessageComposer *newMsg(const std::string &msgId = ""); - static MessageComposer *replyMsg(const std::string &msgId, bool all); - static MessageComposer *forwardMsg(const std::string &msgId); + static MessageComposer *newMsg(const RsMessageId &msgId = RsMessageId()); + static MessageComposer *replyMsg(const RsMessageId &msgId, bool all); + static MessageComposer *forwardMsg(const RsMessageId &msgId); /* worker fns */ void setFileList(const std::list&); @@ -208,8 +208,8 @@ private: QHash autoLinkTitleDictionary; QHash autoLinkTargetDictionary; - std::string m_msgParentId; // parent message id - std::string m_sDraftMsgId; // existing message id + RsMessageId m_msgParentId; // parent message id + RsMessageId m_sDraftMsgId; // existing message id enumMessageType m_msgType; std::list m_tagIds; QList tagLabels; diff --git a/retroshare-gui/src/gui/msgs/MessageWidget.cpp b/retroshare-gui/src/gui/msgs/MessageWidget.cpp index 78c2fd956..0777b8c45 100644 --- a/retroshare-gui/src/gui/msgs/MessageWidget.cpp +++ b/retroshare-gui/src/gui/msgs/MessageWidget.cpp @@ -86,14 +86,14 @@ protected: uint msgFlags; }; -MessageWidget *MessageWidget::openMsg(const std::string &msgId, bool window) +MessageWidget *MessageWidget::openMsg(const RsMessageId &msgId, bool window) { - if (msgId.empty()) { + if (msgId.isNull()) { return NULL; } MessageInfo msgInfo; - if (!rsMsgs->getMessage(msgId, msgInfo)) { + if (!rsMsgs->getMessage(RsMessageId(msgId), msgInfo)) { std::cerr << "MessageWidget::openMsg() Couldn't find Msg" << std::endl; return NULL; } @@ -300,7 +300,7 @@ void MessageWidget::togglefileview() void MessageWidget::getcurrentrecommended() { MessageInfo msgInfo; - if (rsMsgs->getMessage(currMsgId, msgInfo) == false) { + if (rsMsgs->getMessage(RsMessageId(currMsgId), msgInfo) == false) { return; } @@ -343,7 +343,7 @@ void MessageWidget::getallrecommended() { /* get Message */ MessageInfo msgInfo; - if (rsMsgs->getMessage(currMsgId, msgInfo) == false) { + if (rsMsgs->getMessage(RsMessageId(currMsgId), msgInfo) == false) { return; } @@ -376,7 +376,7 @@ void MessageWidget::messagesChanged() /* test Message */ MessageInfo msgInfo; - if (rsMsgs->getMessage(currMsgId, msgInfo) == false) { + if (rsMsgs->getMessage(RsMessageId(currMsgId), msgInfo) == false) { /* messages was removed */ if (isWindow) { window()->close(); @@ -404,12 +404,12 @@ void MessageWidget::showTagLabels() { clearTagLabels(); - if (currMsgId.empty()) { + if (currMsgId.isNull()) { return; } MsgTagInfo tagInfo; - rsMsgs->getMessageTag(currMsgId, tagInfo); + rsMsgs->getMessageTag(RsMessageId(currMsgId), tagInfo); if (tagInfo.tagIds.empty() == false) { ui.tagsLabel->setVisible(true); @@ -442,7 +442,7 @@ void MessageWidget::refill() //fill(msg_id) ; } -void MessageWidget::fill(const std::string &msgId) +void MessageWidget::fill(const RsMessageId &msgId) { // if (currMsgId == msgId) { // // message doesn't changed @@ -453,7 +453,7 @@ void MessageWidget::fill(const std::string &msgId) currMsgId = msgId; - if (currMsgId.empty()) { + if (currMsgId.isNull()) { /* blank it */ ui.dateText-> setText(""); ui.toText->setText(""); @@ -483,33 +483,11 @@ void MessageWidget::fill(const std::string &msgId) clearTagLabels(); MessageInfo msgInfo; - if (rsMsgs->getMessage(currMsgId, msgInfo) == false) { + if (rsMsgs->getMessage(RsMessageId(currMsgId), msgInfo) == false) { std::cerr << "MessageWidget::fill() Couldn't find Msg" << std::endl; return; } -// MIME FIXME: Should be real attachments -#if 0 - const std::list &recList = msgInfo.files; - std::list::const_iterator it; - - ui.msgList->clear(); - - QList items; - for (it = recList.begin(); it != recList.end(); it++) { - QTreeWidgetItem *item = new QTreeWidgetItem; - item->setText(COLUMN_FILE_NAME, QString::fromUtf8(it->fname.c_str())); - item->setText(COLUMN_FILE_SIZE, QString::number(it->size)); - item->setText(COLUMN_FILE_HASH, QString::fromStdString(it->hash.toStdString())); - - /* add to the list */ - items.append(item); - } - - /* add the items in! */ - ui.msgList->insertTopLevelItems(0, items); -#endif - /* iterate through the sources */ RetroShareLink link; QString text; @@ -625,12 +603,61 @@ void MessageWidget::fill(const std::string &msgId) ui.subjectText->setText(QString::fromUtf8(msgInfo.header().subject().c_str())); } - std::string body = msgInfo.body().data(); + unsigned int filecount = 0; + std::string body; + if( msgInfo.header().contentType().str() == "multipart/mixed" ){ + QList items; + mimetic::MimeEntityList & parts = msgInfo.body().parts(); + filecount = parts.size() - 1; // first part will be the text body + for( mimetic::MimeEntityList::const_iterator it = parts.begin(); it != parts.end(); it++ ){ + mimetic::MimeEntity * part = *it; + if( part->header().contentType().type() == "text" ){ + body = part->body().data(); + } + else if( part->header().contentType().type() == "application" ){ + part->header().contentType().param( "name" ); + QTreeWidgetItem *item = new QTreeWidgetItem; + item->setText(COLUMN_FILE_NAME, QString::fromUtf8( part->header().contentType().param( "name" ).c_str() )); + items.append(item); + } + } + ui.msgList->insertTopLevelItems(0, items); + } + else if( msgInfo.header().contentType().type() == "multipart/alternative" ){ + // MIME FIXME: + } + else if( msgInfo.header().contentType().type() == "text" ){ + body = msgInfo.body().data(); + } + + + // MIME FIXME: Should be real attachments + #if 0 + const std::list &recList = msgInfo.files; + std::list::const_iterator it; + + ui.msgList->clear(); + + QList items; + for (it = recList.begin(); it != recList.end(); it++) { + QTreeWidgetItem *item = new QTreeWidgetItem; + item->setText(COLUMN_FILE_NAME, QString::fromUtf8(it->fname.c_str())); + item->setText(COLUMN_FILE_SIZE, QString::number(it->size)); + item->setText(COLUMN_FILE_HASH, QString::fromStdString(it->hash.toStdString())); + + /* add to the list */ + items.append(item); + } + + /* add the items in! */ + ui.msgList->insertTopLevelItems(0, items); + #endif + text = RsHtmlMsg(msgInfo.msgflags).formatText(ui.msgText->document(), QString::fromUtf8( body.c_str()), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS | RSHTML_FORMATTEXT_REPLACE_LINKS ); ui.msgText->resetImagesStatus(Settings->getMsgLoadEmbeddedImages() || (msgInfo.msgflags & RS_MSG_LOAD_EMBEDDED_IMAGES)); ui.msgText->setHtml(text); -// MIME FIXME: ui.filesText->setText(QString("(%1 %2)").arg(msgInfo.count).arg(msgInfo.count == 1 ? tr("File") : tr("Files"))); + ui.filesText->setText(QString("(%1 %2)").arg(filecount).arg(filecount == 1 ? tr("File") : tr("Files"))); if (msgInfo.msgflags & RS_MSG_ENCRYPTED) { ui.decryptFrame->show(); @@ -715,7 +742,7 @@ void MessageWidget::reply() { /* put msg on msgBoard, and switch to it. */ - if (currMsgId.empty()) { + if (currMsgId.isNull()) { return; } @@ -734,7 +761,7 @@ void MessageWidget::replyAll() { /* put msg on msgBoard, and switch to it. */ - if (currMsgId.empty()) { + if (currMsgId.isNull()) { return; } @@ -753,7 +780,7 @@ void MessageWidget::forward() { /* put msg on msgBoard, and switch to it. */ - if (currMsgId.empty()) { + if (currMsgId.isNull()) { return; } @@ -787,7 +814,7 @@ void MessageWidget::anchorClicked(const QUrl &url) void MessageWidget::loadImagesAlways() { - if (currMsgId.empty()) { + if (currMsgId.isNull()) { return; } @@ -801,15 +828,15 @@ void MessageWidget::decrypt() } // Force refill - std::string msgId = currMsgId; + RsMessageId msgId = currMsgId; currMsgId.clear(); fill(msgId); } -bool MessageWidget::decryptMsg(const std::string &msgId) +bool MessageWidget::decryptMsg(const RsMessageId &msgId) { - if (msgId.empty()) { + if (msgId.isNull()) { return false; } diff --git a/retroshare-gui/src/gui/msgs/MessageWidget.h b/retroshare-gui/src/gui/msgs/MessageWidget.h index e5808bd68..fe7bb2ca0 100644 --- a/retroshare-gui/src/gui/msgs/MessageWidget.h +++ b/retroshare-gui/src/gui/msgs/MessageWidget.h @@ -24,6 +24,8 @@ #include #include "ui_MessageWidget.h" +#include + class QToolButton; class QAction; @@ -48,18 +50,18 @@ public: MessageWidget(bool controlled, QWidget *parent = 0, Qt::WindowFlags flags = 0); ~MessageWidget(); - static MessageWidget *openMsg(const std::string &msgId, bool window); + static MessageWidget *openMsg(const RsMessageId &msgId, bool window); - std::string msgId() { return currMsgId; } + RsMessageId msgId() { return currMsgId; } void connectAction(enumActionType actionType, QToolButton* button); void connectAction(enumActionType actionType, QAction* action); - void fill(const std::string &msgId); + void fill(const RsMessageId &msgId); void processSettings(const QString &settingsGroup, bool load); QString subject(bool noEmpty); - static bool decryptMsg(const std::string &msgId); + static bool decryptMsg(const RsMessageId &msgId); private slots: void reply(); @@ -90,7 +92,7 @@ private: bool isControlled; bool isWindow; - std::string currMsgId; + RsMessageId currMsgId; unsigned int currMsgFlags; QList tagLabels; diff --git a/retroshare-gui/src/gui/msgs/MessageWindow.cpp b/retroshare-gui/src/gui/msgs/MessageWindow.cpp index 739917a2a..311a2196d 100644 --- a/retroshare-gui/src/gui/msgs/MessageWindow.cpp +++ b/retroshare-gui/src/gui/msgs/MessageWindow.cpp @@ -162,7 +162,7 @@ void MessageWindow::tagAboutToShow() // activate actions MsgTagInfo tagInfo; - rsMsgs->getMessageTag(msgWidget->msgId(), tagInfo); + rsMsgs->getMessageTag(RsMessageId(msgWidget->msgId()), tagInfo); menu->activateActions(tagInfo.tagIds); } @@ -173,7 +173,7 @@ void MessageWindow::tagRemoveAll() return; } - rsMsgs->setMessageTag(msgWidget->msgId(), 0, false); + rsMsgs->setMessageTag(RsMessageId(msgWidget->msgId()), 0, false); } void MessageWindow::tagSet(int tagId, bool set) @@ -186,7 +186,7 @@ void MessageWindow::tagSet(int tagId, bool set) return; } - rsMsgs->setMessageTag(msgWidget->msgId(), tagId, set); + rsMsgs->setMessageTag(RsMessageId(msgWidget->msgId()), tagId, set); } void MessageWindow::setupFileActions()