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 <libemailfunctions/email.h>
00037 #include <libkpimidentities/identity.h>
00038 #include <libkpimidentities/identitymanager.h>
00039 #include "kmmainwin.h"
00040 #include "composer.h"
00041 #include "kmreaderwin.h"
00042 #include "secondarywindow.h"
00043
00044 #include <mimelib/enum.h>
00045
00046 #include <kinputdialog.h>
00047 #include <klocale.h>
00048 #include <kdebug.h>
00049
00050 using namespace KMail;
00051
00052
00053 Callback::Callback( KMMessage* msg, KMReaderWin* readerWin )
00054 : mMsg( msg ), mReaderWin( readerWin ), mReceiverSet( false )
00055 {
00056 }
00057
00058 bool Callback::mailICal( const QString& to, const QString iCal,
00059 const QString& subject ) const
00060 {
00061 kdDebug(5006) << "Mailing message:\n" << iCal << endl;
00062
00063 KMMessage *msg = new KMMessage;
00064 msg->initHeader();
00065 msg->setHeaderField( "Content-Type",
00066 "text/calendar; method=reply; charset=\"utf-8\"" );
00067 msg->setSubject( subject );
00068 msg->setTo( to );
00069 msg->setBody( iCal.utf8() );
00070 msg->setFrom( receiver() );
00071
00072
00073 msg->link( mMsg, KMMsgStatusDeleted );
00074
00075
00076
00077 KConfigGroup options( KMKernel::config(), "Groupware" );
00078 if( !options.readBoolEntry( "LegacyMangleFromToHeaders", true ) ) {
00079
00080 const KPIM::Identity& identity =
00081 kmkernel->identityManager()->identityForAddress( receiver() );
00082 if( identity != KPIM::Identity::null() )
00083
00084 msg->setFrom( identity.fullEmailAddr() );
00085 msg->setHeaderField("X-KMail-Identity", QString::number( identity.uoid() ));
00086
00087 msg->setBcc( "" );
00088 }
00089
00090 KMail::Composer * cWin = KMail::makeComposer();
00091 cWin->setMsg( msg, false );
00092
00093 cWin->slotWordWrapToggled( false );
00094 cWin->setSigningAndEncryptionDisabled( true );
00095
00096 if ( options.readBoolEntry( "AutomaticSending", true ) ) {
00097 cWin->setAutoDeleteWindow( true );
00098 cWin->slotSendNow();
00099 } else {
00100 cWin->show();
00101 }
00102
00103 return true;
00104 }
00105
00106 QString Callback::receiver() const
00107 {
00108 if ( mReceiverSet )
00109
00110 return mReceiver;
00111
00112 mReceiverSet = true;
00113
00114 QStringList addrs = KPIM::splitEmailAddrList( mMsg->to() );
00115 if( addrs.count() < 2 )
00116
00117 mReceiver = mMsg->to();
00118 else {
00119 int found = 0;
00120 for( QStringList::Iterator it = addrs.begin(); it != addrs.end(); ++it ) {
00121 if( kmkernel->identityManager()->identityForAddress( *it ) !=
00122 KPIM::Identity::null() ) {
00123
00124 ++found;
00125 mReceiver = *it;
00126 }
00127 }
00128
00129 if( found != 1 ) {
00130 bool ok;
00131 mReceiver =
00132 KInputDialog::getItem( i18n( "Select Address" ),
00133 i18n( "<qt>None of your identities match the "
00134 "receiver of this message,<br>please "
00135 "choose which of the following addresses "
00136 "is yours:" ),
00137 addrs, 0, FALSE, &ok, kmkernel->mainWin() );
00138 if( !ok )
00139 mReceiver = QString::null;
00140 }
00141 }
00142
00143 return mReceiver;
00144 }
00145
00146 void Callback::closeIfSecondaryWindow() const
00147 {
00148 KMail::SecondaryWindow *window = dynamic_cast<KMail::SecondaryWindow*>( mReaderWin->mainWindow() );
00149 if ( window )
00150 window->close();
00151 }
|