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