kmail
callback.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "callback.h"
00034 #include "kmkernel.h"
00035 #include "kmmessage.h"
00036 #include "kmmsgpart.h"
00037 #include <libemailfunctions/email.h>
00038 #include <libkpimidentities/identity.h>
00039 #include <libkpimidentities/identitymanager.h>
00040 #include "kmmainwin.h"
00041 #include "composer.h"
00042 #include "kmreaderwin.h"
00043 #include "secondarywindow.h"
00044
00045 #include <mimelib/enum.h>
00046
00047 #include <kinputdialog.h>
00048 #include <klocale.h>
00049 #include <kdebug.h>
00050
00051 using namespace KMail;
00052
00053
00054 Callback::Callback( KMMessage* msg, KMReaderWin* readerWin )
00055 : mMsg( msg ), mReaderWin( readerWin ), mReceiverSet( false )
00056 {
00057 }
00058
00059 bool Callback::mailICal( const QString& to, const QString &iCal,
00060 const QString& subject, const QString &status,
00061 bool delMessage ) const
00062 {
00063 kdDebug(5006) << "Mailing message:\n" << iCal << endl;
00064
00065 KMMessage *msg = new KMMessage;
00066 msg->initHeader();
00067 msg->setSubject( subject );
00068 if ( GlobalSettings::self()->exchangeCompatibleInvitations() ) {
00069 if ( status == QString("cancel") )
00070 msg->setSubject( QString("Declined: %1").arg(subject).replace("Answer: ","") );
00071 else if ( status == QString("tentative") )
00072 msg->setSubject(QString("Tentative: %1").arg(subject).replace("Answer: ","") );
00073 else if ( status == QString("accepted") )
00074 msg->setSubject( QString("Accepted: %1").arg(subject).replace("Answer: ","") );
00075 else if ( status == QString("delegated") )
00076 msg->setSubject( QString("Delegated: %1").arg(subject).replace("Answer: ","") );
00077 }
00078 msg->setTo( to );
00079 msg->setFrom( receiver() );
00080
00081 if ( !GlobalSettings::self()->exchangeCompatibleInvitations() ) {
00082 msg->setHeaderField( "Content-Type",
00083 "text/calendar; method=reply; charset=\"utf-8\"" );
00084 msg->setBody( iCal.utf8() );
00085 }
00086
00087 if ( delMessage && deleteInvitationAfterReply() )
00088
00089
00090 msg->link( mMsg, KMMsgStatusDeleted );
00091
00092
00093
00094 KConfigGroup options( KMKernel::config(), "Groupware" );
00095 if( !options.readBoolEntry( "LegacyMangleFromToHeaders", true ) ) {
00096
00097 const KPIM::Identity& identity =
00098 kmkernel->identityManager()->identityForAddress( receiver() );
00099 if( identity != KPIM::Identity::null() ) {
00100
00101 msg->setFrom( identity.fullEmailAddr() );
00102 msg->setHeaderField("X-KMail-Identity", QString::number( identity.uoid() ));
00103 }
00104
00105 msg->setBcc( "" );
00106 }
00107
00108 KMail::Composer * cWin = KMail::makeComposer();
00109 cWin->setMsg( msg, false );
00110
00111 cWin->disableWordWrap();
00112 cWin->setSigningAndEncryptionDisabled( true );
00113
00114 if( GlobalSettings::self()->exchangeCompatibleInvitations() ) {
00115
00116
00117 msg->setSubject( status );
00118 msg->setCharset( "utf-8" );
00119 KMMessagePart *msgPart = new KMMessagePart;
00120 msgPart->setName( "cal.ics" );
00121
00122 msgPart->setBodyEncoded( iCal.utf8() );
00123 msgPart->setTypeStr( "text" );
00124 msgPart->setSubtypeStr( "calendar" );
00125 msgPart->setParameter( "method", "reply" );
00126 cWin->addAttach( msgPart );
00127 }
00128
00129 cWin->disableRecipientNumberCheck();
00130 if ( options.readBoolEntry( "AutomaticSending", true ) ) {
00131 cWin->setAutoDeleteWindow( true );
00132 cWin->slotSendNow();
00133 } else {
00134 cWin->show();
00135 }
00136
00137 return true;
00138 }
00139
00140 QString Callback::receiver() const
00141 {
00142 if ( mReceiverSet )
00143
00144 return mReceiver;
00145
00146 mReceiverSet = true;
00147
00148 QStringList addrs = KPIM::splitEmailAddrList( mMsg->to() );
00149 int found = 0;
00150 for( QStringList::Iterator it = addrs.begin(); it != addrs.end(); ++it ) {
00151 if( kmkernel->identityManager()->identityForAddress( *it ) !=
00152 KPIM::Identity::null() ) {
00153
00154 ++found;
00155 mReceiver = *it;
00156 }
00157 }
00158 QStringList ccaddrs = KPIM::splitEmailAddrList( mMsg->cc() );
00159 for( QStringList::Iterator it = ccaddrs.begin(); it != ccaddrs.end(); ++it ) {
00160 if( kmkernel->identityManager()->identityForAddress( *it ) !=
00161 KPIM::Identity::null() ) {
00162
00163 ++found;
00164 mReceiver = *it;
00165 }
00166 }
00167 if( found != 1 ) {
00168 bool ok;
00169 QString selectMessage;
00170 if (found == 0) {
00171 selectMessage = i18n("<qt>None of your identities match the "
00172 "receiver of this message,<br>please "
00173 "choose which of the following addresses "
00174 "is yours, if any, or select one of your identities to use in the reply:");
00175 addrs += kmkernel->identityManager()->allEmails();
00176 } else {
00177 selectMessage = i18n("<qt>Several of your identities match the "
00178 "receiver of this message,<br>please "
00179 "choose which of the following addresses "
00180 "is yours:");
00181 }
00182
00183
00184 const QString defaultAddr = kmkernel->identityManager()->defaultIdentity().emailAddr();
00185 const int defaultIndex = QMAX( 0, addrs.findIndex( defaultAddr ) );
00186
00187 mReceiver =
00188 KInputDialog::getItem( i18n( "Select Address" ),
00189 selectMessage,
00190 addrs+ccaddrs, defaultIndex, FALSE, &ok, kmkernel->mainWin() );
00191 if( !ok )
00192 mReceiver = QString::null;
00193 }
00194
00195 return mReceiver;
00196 }
00197
00198 void Callback::closeIfSecondaryWindow() const
00199 {
00200 KMail::SecondaryWindow *window = dynamic_cast<KMail::SecondaryWindow*>( mReaderWin->mainWindow() );
00201 if ( window )
00202 window->close();
00203 }
00204
00205 bool Callback::askForComment( KCal::Attendee::PartStat status ) const
00206 {
00207 if ( ( status != KCal::Attendee::Accepted
00208 && GlobalSettings::self()->askForCommentWhenReactingToInvitation()
00209 == GlobalSettings:: EnumAskForCommentWhenReactingToInvitation::AskForAllButAcceptance )
00210 || GlobalSettings::self()->askForCommentWhenReactingToInvitation()
00211 == GlobalSettings:: EnumAskForCommentWhenReactingToInvitation::AlwaysAsk )
00212 return true;
00213 return false;
00214 }
00215
00216 bool Callback::deleteInvitationAfterReply() const
00217 {
00218 return GlobalSettings::self()->deleteInvitationEmailsAfterSendingReply();
00219 }
00220
00221 bool Callback::exchangeCompatibleInvitations() const
00222 {
00223 return GlobalSettings::self()->exchangeCompatibleInvitations();
00224 }
00225
00226 bool Callback::outlookCompatibleInvitationReplyComments() const
00227 {
00228 return GlobalSettings::self()->outlookCompatibleInvitationReplyComments();
00229 }
00230
00231 QString Callback::sender() const
00232 {
00233 return mMsg->from();
00234 }
|