callback.cpp
00001
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 <libkdepim/email.h>
00037 #include <libkpimidentities/identity.h>
00038 #include <libkpimidentities/identitymanager.h>
00039 #include "kmmainwin.h"
00040 #include "kmcomposewin.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 if ( receiver().isEmpty() )
00064
00065 return false;
00066
00067 KMMessage *msg = new KMMessage;
00068 msg->initHeader();
00069 msg->setHeaderField( "Content-Type",
00070 "text/calendar; method=reply; charset=\"utf-8\"" );
00071 msg->setSubject( subject );
00072 msg->setTo( to );
00073 msg->setBody( iCal.utf8() );
00074 msg->setFrom( receiver() );
00075
00076
00077 msg->link( mMsg, KMMsgStatusDeleted );
00078
00079
00080
00081 KConfigGroup options( KMKernel::config(), "Groupware" );
00082 if( !options.readBoolEntry( "LegacyMangleFromToHeaders", true ) ) {
00083
00084 const KPIM::Identity& identity =
00085 kmkernel->identityManager()->identityForAddress( receiver() );
00086 if( identity != KPIM::Identity::null() ) {
00087
00088 msg->setFrom( identity.fullEmailAddr() );
00089 msg->setHeaderField( "X-KMail-Identity",
00090 QString::number( identity.uoid() ) );
00091
00092
00093 msg->setBcc( "" );
00094 }
00095 }
00096
00097 KMComposeWin *cWin = new KMComposeWin();
00098 cWin->setMsg( msg, false );
00099
00100 cWin->slotWordWrapToggled( false );
00101 cWin->setSigningAndEncryptionDisabled( true );
00102
00103 if ( options.readBoolEntry( "AutomaticSending", true ) ) {
00104 cWin->setAutoDeleteWindow( true );
00105 cWin->slotSendNow();
00106 } else {
00107 cWin->show();
00108 }
00109
00110 return true;
00111 }
00112
00113 QString Callback::receiver() const
00114 {
00115 if ( mReceiverSet )
00116
00117 return mReceiver;
00118
00119
00120 mReceiverSet = true;
00121
00122 QStringList addrs = KPIM::splitEmailAddrList( mMsg->to() );
00123 int found = 0;
00124 for( QStringList::Iterator it = addrs.begin(); it != addrs.end(); ++it )
00125 if( kmkernel->identityManager()->identityForAddress( *it )
00126 != KPIM::Identity::null() ) {
00127
00128 ++found;
00129 mReceiver = *it;
00130 }
00131
00132 if( found != 1 ) {
00133 bool ok;
00134 const QString message =
00135 i18n( "<qt>If you received this personally, please choose which of<br>"
00136 "the following addresses is yours.<br><br>"
00137 "If you received this from a distribution list, then choose<br>"
00138 "which of your own identities to reply with." );
00139
00140
00141 QStringList toShow = addrs;
00142
00143
00144 const int receivers = addrs.count();
00145
00146
00147 KPIM::IdentityManager::ConstIterator it =
00148 kmkernel->identityManager()->begin();
00149 KPIM::IdentityManager::ConstIterator end =
00150 kmkernel->identityManager()->end();
00151 int defaultIdx = 0;
00152 for ( int i = 0; it != end; ++it, ++i ) {
00153 const QString addr = (*it).fullEmailAddr();
00154 addrs << addr;
00155 toShow << i18n( "Identity: %1" ).arg( addr );
00156 if ( (*it).isDefault() ) defaultIdx = i;
00157 }
00158
00159
00160 mReceiver =
00161 KInputDialog::getItem( i18n( "Select Address" ), message,
00162 toShow, defaultIdx, false, &ok, kmkernel->mainWin() );
00163 if( !ok ) {
00164 mReceiver = QString::null;
00165
00166
00167 mReceiverSet = false;
00168 } else {
00169
00170 const int i = toShow.findIndex( mReceiver );
00171 if ( i >= receivers )
00172
00173 mReceiver = addrs[ i ];
00174 }
00175 }
00176
00177 kdDebug(5006) << "Receiver: " << mReceiver << endl;
00178
00179 return mReceiver;
00180 }
00181
00182 void Callback::closeIfSecondaryWindow() const
00183 {
00184 KMail::SecondaryWindow *window = dynamic_cast<KMail::SecondaryWindow*>( mReaderWin->mainWindow() );
00185 if ( window )
00186 window->close();
00187 }
This file is part of the documentation for kmail Library Version 3.3.2.