35 #include "kmmessage.h"
36 #include "kmmsgpart.h"
37 #include <libemailfunctions/email.h>
38 #include <libkpimidentities/identity.h>
39 #include <libkpimidentities/identitymanager.h>
40 #include "kmmainwin.h"
42 #include "kmreaderwin.h"
43 #include "secondarywindow.h"
44 #include "transportmanager.h"
46 #include <mimelib/enum.h>
48 #include <kinputdialog.h>
49 #include <tdelocale.h>
52 using namespace KMail;
56 : mMsg( msg ), mReaderWin( readerWin ), mReceiverSet( false )
60 TQString Callback::askForTransport(
bool nullIdentity )
const
63 if ( transports.size() == 1 )
64 return transports.first();
66 const TQString defaultTransport = GlobalSettings::self()->defaultTransport();
67 const int defaultIndex = TQMAX( 0, transports.findIndex( defaultTransport ) );
71 text = i18n(
"<qt>The receiver of this invitation doesn't match any of your identities.<br>"
72 "Please select the transport which should be used to send your reply.</qt>" );
74 text = i18n(
"<qt>The identity matching the receiver of this invitation doesn't have an "
75 "associated transport configured.<br>"
76 "Please select the transport which should be used to send your reply.</qt>");
78 const TQString transport = KInputDialog::getItem( i18n(
"Select Transport" ), text,
79 transports, defaultIndex, FALSE, &ok, kmkernel->mainWin() );
87 const TQString& subject,
const TQString &status,
88 bool delMessage )
const
90 kdDebug(5006) <<
"Mailing message:\n" << iCal << endl;
94 msg->setSubject( subject );
95 if ( GlobalSettings::self()->exchangeCompatibleInvitations() ) {
96 if ( status == TQString(
"cancel") )
97 msg->setSubject( i18n(
"Declined: %1" ).arg(subject).replace(
"Answer: ",
"") );
98 else if ( status == TQString(
"tentative") )
99 msg->setSubject( i18n(
"Tentative: %1" ).arg(subject).replace(
"Answer: ",
"") );
100 else if ( status == TQString(
"accepted") )
101 msg->setSubject( i18n(
"Accepted: %1" ).arg(subject).replace(
"Answer: ",
"") );
102 else if ( status == TQString(
"delegated") )
103 msg->setSubject( i18n(
"Delegated: %1" ).arg(subject).replace(
"Answer: ",
"") );
106 msg->setFrom( receiver() );
108 if ( !GlobalSettings::self()->exchangeCompatibleInvitations() ) {
110 "text/calendar; method=reply; charset=\"utf-8\"" );
114 if ( delMessage && deleteInvitationAfterReply() )
117 msg->
link( mMsg, KMMsgStatusDeleted );
122 const KPIM::Identity& identity = kmkernel->identityManager()->identityForAddress( receiver() );
123 const bool nullIdentity = ( identity == KPIM::Identity::null() );
124 if ( !nullIdentity ) {
125 msg->
setHeaderField(
"X-KMail-Identity", TQString::number( identity.uoid() ));
128 const bool identityHasTransport = !identity.transport().isEmpty();
129 if ( !nullIdentity && identityHasTransport )
131 else if ( !nullIdentity && identity.isDefault() )
132 msg->
setHeaderField(
"X-KMail-Transport", GlobalSettings::self()->defaultTransport() );
134 const TQString transport = askForTransport( nullIdentity );
135 if ( transport.isEmpty() )
142 TDEConfigGroup options( KMKernel::config(),
"Groupware" );
143 if( !options.readBoolEntry(
"LegacyMangleFromToHeaders",
true ) ) {
144 if( identity != KPIM::Identity::null() ) {
145 msg->setFrom( identity.fullEmailAddr() );
151 KMail::Composer * cWin = KMail::makeComposer();
152 cWin->ignoreStickyFields();
153 cWin->setMsg( msg,
false );
155 cWin->disableWordWrap();
156 cWin->setSigningAndEncryptionDisabled(
true );
158 if( GlobalSettings::self()->exchangeCompatibleInvitations() ) {
161 msg->setSubject( status );
163 KMMessagePart *msgPart =
new KMMessagePart;
164 msgPart->setName(
"cal.ics" );
166 msgPart->setBodyEncoded( iCal.utf8() );
167 msgPart->setTypeStr(
"text" );
168 msgPart->setSubtypeStr(
"calendar" );
169 msgPart->setParameter(
"method",
"reply" );
170 cWin->addAttach( msgPart );
173 cWin->disableRecipientNumberCheck();
174 cWin->disableForgottenAttachmentsCheck();
175 if ( options.readBoolEntry(
"AutomaticSending",
true ) ) {
176 cWin->setAutoDeleteWindow(
true );
193 TQStringList addrs = KPIM::splitEmailAddrList( mMsg->to() );
195 for( TQStringList::Iterator it = addrs.begin(); it != addrs.end(); ++it ) {
196 if( kmkernel->identityManager()->identityForAddress( *it ) !=
197 KPIM::Identity::null() ) {
203 TQStringList ccaddrs = KPIM::splitEmailAddrList( mMsg->cc() );
204 for( TQStringList::Iterator it = ccaddrs.begin(); it != ccaddrs.end(); ++it ) {
205 if( kmkernel->identityManager()->identityForAddress( *it ) !=
206 KPIM::Identity::null() ) {
214 TQString selectMessage;
216 selectMessage = i18n(
"<qt>None of your identities match the "
217 "receiver of this message,<br>please "
218 "choose which of the following addresses "
219 "is yours, if any, or select one of your identities to use in the reply:");
220 addrs += kmkernel->identityManager()->allEmails();
222 selectMessage = i18n(
"<qt>Several of your identities match the "
223 "receiver of this message,<br>please "
224 "choose which of the following addresses "
229 const TQString defaultAddr = kmkernel->identityManager()->defaultIdentity().primaryEmailAddress();
230 const int defaultIndex = TQMAX( 0, addrs.findIndex( defaultAddr ) );
233 KInputDialog::getItem( i18n(
"Select Address" ),
235 addrs+ccaddrs, defaultIndex, FALSE, &ok, kmkernel->mainWin() );
237 mReceiver = TQString();
250 bool Callback::askForComment( KCal::Attendee::PartStat status )
const
252 if ( ( status != KCal::Attendee::Accepted
253 && GlobalSettings::self()->askForCommentWhenReactingToInvitation()
254 == GlobalSettings:: EnumAskForCommentWhenReactingToInvitation::AskForAllButAcceptance )
255 || GlobalSettings::self()->askForCommentWhenReactingToInvitation()
256 == GlobalSettings:: EnumAskForCommentWhenReactingToInvitation::AlwaysAsk )
261 bool Callback::deleteInvitationAfterReply()
const
263 return GlobalSettings::self()->deleteInvitationEmailsAfterSendingReply();
266 bool Callback::exchangeCompatibleInvitations()
const
268 return GlobalSettings::self()->exchangeCompatibleInvitations();
271 bool Callback::outlookCompatibleInvitationReplyComments()
const
273 return GlobalSettings::self()->outlookCompatibleInvitationReplyComments();