• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

mailcommon

  • sources
  • kde-4.12
  • kdepim
  • mailcommon
  • mdn
sendmdnhandler.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net,
3  Author Tobias Koenig <tokoe@kdab.com>
4 
5  This library is free software; you can redistribute it and/or modify it
6  under the terms of the GNU Library General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or (at your
8  option) any later version.
9 
10  This library is distributed in the hope that it will be useful, but WITHOUT
11  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13  License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to the
17  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  02110-1301, USA.
19 */
20 
21 #include "sendmdnhandler.h"
22 
23 #include "interfaces/mailinterfaces.h"
24 #include "kernel/mailkernel.h"
25 #include "util/mailutil.h"
26 #include "mdnadvicedialog.h"
27 
28 #include <messagecomposer/helper/messagefactory.h>
29 #include <messagecomposer/sender/messagesender.h>
30 #include <messagecore/helpers/messagehelpers.h>
31 #include <messageviewer/settings/globalsettings.h>
32 
33 #include <Akonadi/Collection>
34 #include <Akonadi/Item>
35 #include <Akonadi/KMime/MessageFlags>
36 
37 #include <QQueue>
38 #include <QTimer>
39 
40 using namespace MailCommon;
41 
42 class SendMdnHandler::Private
43 {
44  public:
45  Private( SendMdnHandler *qq, IKernel *kernel )
46  : q( qq ), mKernel( kernel )
47  {
48  }
49 
50  void handleMessages();
51 
52  SendMdnHandler *q;
53  IKernel *mKernel;
54  QQueue<Akonadi::Item> mItemQueue;
55  QTimer mTimer;
56 };
57 
58 void SendMdnHandler::Private::handleMessages()
59 {
60  while ( !mItemQueue.isEmpty() ) {
61  Akonadi::Item item = mItemQueue.dequeue();
62 
63 #if 0
64  // should we send an MDN?
65  if ( MessageViewer::GlobalSettings::notSendWhenEncrypted() &&
66  message()->encryptionState() != KMMsgNotEncrypted &&
67  message()->encryptionState() != KMMsgEncryptionStateUnknown ) {
68  return;
69  }
70 #else
71  kDebug() << "AKONADI PORT: Disabled code in " << Q_FUNC_INFO;
72 #endif
73 
74  const Akonadi::Collection collection = item.parentCollection();
75  if ( collection.isValid() &&
76  ( CommonKernel->folderIsSentMailFolder( collection ) ||
77  CommonKernel->folderIsTrash( collection ) ||
78  CommonKernel->folderIsDraftOrOutbox( collection ) ||
79  CommonKernel->folderIsTemplates( collection ) ) ) {
80  continue;
81  }
82 
83  const KMime::Message::Ptr message = MessageCore::Util::message( item );
84  if ( !message ) {
85  continue;
86  }
87 
88  const QPair<bool, KMime::MDN::SendingMode> mdnSend =
89  MDNAdviceHelper::instance()->checkAndSetMDNInfo( item, KMime::MDN::Displayed );
90  if ( mdnSend.first ) {
91  const int quote = MessageViewer::GlobalSettings::self()->quoteMessage();
92 
93  MessageComposer::MessageFactory factory( message, Akonadi::Item().id() );
94  factory.setIdentityManager( mKernel->identityManager() );
95  factory.setFolderIdentity( MailCommon::Util::folderIdentity( item ) );
96 
97  const KMime::Message::Ptr mdn =
98  factory.createMDN( KMime::MDN::ManualAction, KMime::MDN::Displayed, mdnSend.second, quote );
99  if ( mdn ) {
100  if ( !mKernel->msgSender()->send( mdn ) ) {
101  kDebug() << "Sending failed.";
102  }
103  }
104  }
105  }
106 }
107 
108 SendMdnHandler::SendMdnHandler( IKernel *kernel, QObject *parent )
109  : QObject( parent ), d( new Private( this, kernel ) )
110 {
111  d->mTimer.setSingleShot( true );
112  connect( &d->mTimer, SIGNAL(timeout()), this, SLOT(handleMessages()) );
113 }
114 
115 SendMdnHandler::~SendMdnHandler()
116 {
117  delete d;
118 }
119 
120 void SendMdnHandler::setItem( const Akonadi::Item &item )
121 {
122  if ( item.hasFlag( Akonadi::MessageFlags::Seen ) ) {
123  return;
124  }
125 
126  d->mTimer.stop();
127 
128  d->mItemQueue.enqueue( item );
129 
130  if ( MessageViewer::GlobalSettings::self()->delayedMarkAsRead() &&
131  MessageViewer::GlobalSettings::self()->delayedMarkTime() != 0 ) {
132  d->mTimer.start( MessageViewer::GlobalSettings::self()->delayedMarkTime() * 1000 );
133  return;
134  }
135 
136  d->handleMessages();
137 }
138 
139 #include "sendmdnhandler.moc"
MailCommon::SendMdnHandler
A viewer handler to send MDN for viewed messages.
Definition: sendmdnhandler.h:37
MailCommon::SendMdnHandler::SendMdnHandler
SendMdnHandler(IKernel *kernel, QObject *parent=0)
Creates a new send mnd handler.
Definition: sendmdnhandler.cpp:108
mailinterfaces.h
QObject
mdnadvicedialog.h
MailCommon::SendMdnHandler::setItem
virtual void setItem(const Akonadi::Item &item)
Definition: sendmdnhandler.cpp:120
MailCommon::MDNAdviceHelper::checkAndSetMDNInfo
QPair< bool, KMime::MDN::SendingMode > checkAndSetMDNInfo(const Akonadi::Item &item, KMime::MDN::DispositionType d, bool forceSend=false)
Checks the MDN headers to see if the user needs to be asked for any confirmations.
Definition: mdnadvicedialog.cpp:135
MailCommon::SendMdnHandler::~SendMdnHandler
~SendMdnHandler()
Destroys the send mdn handler.
Definition: sendmdnhandler.cpp:115
CommonKernel
#define CommonKernel
Definition: mailkernel.h:189
MailCommon::Util::folderIdentity
MAILCOMMON_EXPORT uint folderIdentity(const Akonadi::Item &item)
Returns the identity of the folder that contains the given Akonadi::Item.
Definition: mailutil.cpp:446
mailkernel.h
sendmdnhandler.h
MailCommon::MDNAdviceHelper::instance
static MDNAdviceHelper * instance()
Definition: mdnadvicedialog.h:36
MailCommon::IKernel
Generic interface for mail kernels.
Definition: mailinterfaces.h:45
mailutil.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:15 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

mailcommon

Skip menu "mailcommon"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal