diff --git a/foldercollection.cpp b/foldercollection.cpp index ae04e635b..e5561b32e 100644 --- a/foldercollection.cpp +++ b/foldercollection.cpp @@ -330,6 +330,20 @@ void FolderCollection::setReadExpireUnits( ExpireUnits units ) } } +QString FolderCollection::mailingListPostAddress() const +{ + if ( mMailingList.features() & MailingList::Post ) { + KUrl::List::const_iterator it; + KUrl::List post = mMailingList.postURLS(); + for( it = post.constBegin(); it != post.constEnd(); ++it ) { + // We check for isEmpty because before 3.3 postAddress was just an + // email@kde.org and that leaves protocol() field in the kurl class + if ( (*it).protocol() == "mailto" || (*it).protocol().isEmpty() ) + return (*it).path(); + } + } + return QString(); +} void FolderCollection::setExpireAction( ExpireAction a ) { diff --git a/foldercollection.h b/foldercollection.h index 81dd3603e..e9463428b 100644 --- a/foldercollection.h +++ b/foldercollection.h @@ -187,6 +187,7 @@ public: bool ignoreNewMail() const { return mIgnoreNewMail; } void setIgnoreNewMail( bool b ) { mIgnoreNewMail = b; } + QString mailingListPostAddress() const; /** Mark all new messages as unread. */ void markNewAsUnread(); diff --git a/kmcommands.cpp b/kmcommands.cpp index b9176dcf8..d0b51fbae 100644 --- a/kmcommands.cpp +++ b/kmcommands.cpp @@ -1109,7 +1109,7 @@ KMCommand::Result KMReplyToCommand::execute() KMime::Message::Ptr msg = KMail::Util::message( item ); if ( !msg ) return Failed; - KMail::MessageHelper::MessageReply reply = KMail::MessageHelper::createReply2( &*msg, KMail::ReplySmart, mSelection ); + KMail::MessageHelper::MessageReply reply = KMail::MessageHelper::createReply2( item, &*msg, KMail::ReplySmart, mSelection ); KMail::Composer * win = KMail::makeComposer( reply.msg, replyContext( reply ), 0, mSelection ); #if 0 //Port to kmime::message win->setCharset( msg->codec()->name(), true ); @@ -1140,7 +1140,7 @@ KMCommand::Result KMNoQuoteReplyToCommand::execute() KMime::Message::Ptr msg = KMail::Util::message( item ); if ( !msg ) return Failed; - KMail::MessageHelper::MessageReply reply = KMail::MessageHelper::createReply2( &*msg, KMail::ReplySmart, "", true); + KMail::MessageHelper::MessageReply reply = KMail::MessageHelper::createReply2( item, &*msg, KMail::ReplySmart, "", true); KMail::Composer *win = KMail::makeComposer( reply.msg, replyContext( reply ) ); #if 0 //Port to akonadi win->setCharset( msg->codec()->name(), true ); @@ -1170,7 +1170,7 @@ KMCommand::Result KMReplyListCommand::execute() KMime::Message::Ptr msg = KMail::Util::message( item ); if ( !msg ) return Failed; - KMail::MessageHelper::MessageReply reply = KMail::MessageHelper::createReply2( &*msg, KMail::ReplyList, mSelection ); + KMail::MessageHelper::MessageReply reply = KMail::MessageHelper::createReply2( item, &*msg, KMail::ReplyList, mSelection ); KMail::Composer * win = KMail::makeComposer( reply.msg, replyContext( reply ), 0, mSelection ); #if 0 @@ -1202,7 +1202,7 @@ KMCommand::Result KMReplyToAllCommand::execute() KMime::Message::Ptr msg = KMail::Util::message( item ); if ( !msg ) return Failed; - KMail::MessageHelper::MessageReply reply = KMail::MessageHelper::createReply2( &*msg, KMail::ReplyAll, mSelection ); + KMail::MessageHelper::MessageReply reply = KMail::MessageHelper::createReply2( item, &*msg, KMail::ReplyAll, mSelection ); KMail::Composer * win = KMail::makeComposer( reply.msg, replyContext( reply ), 0, mSelection ); #if 0 @@ -1233,7 +1233,7 @@ KMCommand::Result KMReplyAuthorCommand::execute() KMime::Message::Ptr msg = KMail::Util::message( item ); if ( !msg ) return Failed; - KMail::MessageHelper::MessageReply reply = KMail::MessageHelper::createReply2( &*msg, KMail::ReplyAuthor, mSelection ); + KMail::MessageHelper::MessageReply reply = KMail::MessageHelper::createReply2( item, &*msg, KMail::ReplyAuthor, mSelection ); KMail::Composer * win = KMail::makeComposer( reply.msg, replyContext( reply ), 0, mSelection ); #if 0 @@ -1534,7 +1534,7 @@ KMCommand::Result KMCustomReplyToCommand::execute() KMime::Message::Ptr msg = KMail::Util::message( item ); if ( !msg ) return Failed; - KMail::MessageHelper::MessageReply reply = KMail::MessageHelper::createReply2( &*msg, KMail::ReplySmart, mSelection, + KMail::MessageHelper::MessageReply reply = KMail::MessageHelper::createReply2( item, &*msg, KMail::ReplySmart, mSelection, false, true, false, mTemplate ); KMail::Composer * win = KMail::makeComposer( reply.msg, replyContext( reply ), 0, mSelection, mTemplate ); @@ -1568,7 +1568,7 @@ KMCommand::Result KMCustomReplyAllToCommand::execute() KMime::Message::Ptr msg = KMail::Util::message( item ); if ( !msg ) return Failed; - KMail::MessageHelper::MessageReply reply = KMail::MessageHelper::createReply2( &*msg, KMail::ReplyAll, mSelection, + KMail::MessageHelper::MessageReply reply = KMail::MessageHelper::createReply2( item, &*msg, KMail::ReplyAll, mSelection, false, true, false, mTemplate ); KMail::Composer * win = KMail::makeComposer( reply.msg, replyContext( reply ), 0, mSelection, mTemplate ); diff --git a/messagehelper.cpp b/messagehelper.cpp index c0be2111c..ee18a779f 100644 --- a/messagehelper.cpp +++ b/messagehelper.cpp @@ -27,6 +27,7 @@ #include "messageinfo.h" #include "mdnadvicedialog.h" #include "mailinglist-magic.h" +#include "foldercollection.h" #include #include @@ -450,13 +451,14 @@ msg->link( this, MessageStatus::statusReplied() ); return msg; } -MessageReply createReply2( KMime::Message *origMsg, - KMail::ReplyStrategy replyStrategy, - const QString &selection /*.clear() */, - bool noQuote /* = false */, - bool allowDecryption /* = true */, - bool selectionIsBody /* = false */, - const QString &tmpl /* = QString() */ ) +MessageReply createReply2(const Akonadi::Item &item, + KMime::Message *origMsg, + KMail::ReplyStrategy replyStrategy, + const QString &selection /*.clear() */, + bool noQuote /* = false */, + bool allowDecryption /* = true */, + bool selectionIsBody /* = false */, + const QString &tmpl /* = QString() */ ) { KMime::Message* msg = new KMime::Message; QString str, mailingListStr, replyToStr, toStr; @@ -469,15 +471,15 @@ MessageReply createReply2( KMime::Message *origMsg, replyToStr = origMsg->replyTo()->asUnicodeString(); msg->contentType()->setCharset("utf-8"); -#if 0 //TODO port to akonadi // determine the mailing list posting address - if ( parent() && parent()->isMailingListEnabled() && - !parent()->mailingListPostAddress().isEmpty() ) { - mailingListAddresses << parent()->mailingListPostAddress(); + Akonadi::Collection parentCollection = item.parentCollection(); + FolderCollection *fd = 0; + if ( parentCollection.isValid() ) { + fd = new FolderCollection( parentCollection, false /*don't save*/ ); + if ( fd->isMailingListEnabled() && !fd->mailingListPostAddress().isEmpty() ) { + mailingListAddresses << fd->mailingListPostAddress(); + } } -#else - kDebug() << "AKONADI PORT: Disabled code in " << Q_FUNC_INFO; -#endif if ( origMsg->headerByType("List-Post") && origMsg->headerByType("List-Post")->asUnicodeString().contains( "mailto:", Qt::CaseInsensitive ) ) { QString listPost = origMsg->headerByType("List-Post")->asUnicodeString(); @@ -658,9 +660,12 @@ MessageReply createReply2( KMime::Message *origMsg, } #if 0 //TODO port to akonadi msg->link( this, MessageStatus::statusReplied() ); - if ( parent() && parent()->putRepliesInSameFolder() ) - msg->setFcc( parent()->idString() ); - +#endif + if ( parentCollection.isValid() && fd->putRepliesInSameFolder() ) { + KMime::Headers::Generic *header = new KMime::Headers::Generic( "X-KMail-Fcc", msg, QString::number( parentCollection.id() ), "utf-8" ); + msg->setHeader( header ); + } +#if 0 // replies to an encrypted message should be encrypted as well if ( encryptionState() == KMMsgPartiallyEncrypted || encryptionState() == KMMsgFullyEncrypted ) { @@ -674,6 +679,7 @@ MessageReply createReply2( KMime::Message *origMsg, MessageReply reply; reply.msg = msg; reply.replyAll = replyAll; + delete fd; return reply; } diff --git a/messagehelper.h b/messagehelper.h index cd4821b2a..d7be00049 100644 --- a/messagehelper.h +++ b/messagehelper.h @@ -22,7 +22,7 @@ #include #include - +#include namespace KMail { /** * Enumeration that defines the available reply "modes" @@ -68,7 +68,7 @@ namespace MessageHelper { /** Create a new message that is a reply to this message, filling all required header fields with the proper values. The returned message is not stored in any folder. Marks this message as replied. */ - KMime::Message* createReply( KMime::Message* origMsg, KMail::ReplyStrategy replyStrategy = KMail::ReplySmart, + KMime::Message* createReply(KMime::Message* origMsg, KMail::ReplyStrategy replyStrategy = KMail::ReplySmart, const QString &selection=QString(), bool noQuote=false, bool allowDecryption=true, bool selectionIsBody=false, const QString &tmpl = QString() ); @@ -82,7 +82,7 @@ namespace MessageHelper { * @return the reply created, including the reply mode */ //TODO see if this can be merged with the above one! - MessageReply createReply2( KMime::Message* origMsg, + MessageReply createReply2( const Akonadi::Item & item, KMime::Message* origMsg, KMail::ReplyStrategy replyStrategy = KMail::ReplySmart, const QString &selection=QString(), bool noQuote=false, bool allowDecryption=true, bool selectionIsBody=false,