kmail

identitydialog.cpp
1/*
2 identitydialog.cpp
3
4 This file is part of KMail, the KDE mail client.
5 Copyright (c) 2002 Marc Mutz <mutz@kde.org>
6
7 KMail is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License, version 2, as
9 published by the Free Software Foundation.
10
11 KMail is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
20 In addition, as a special exception, the copyright holders give
21 permission to link the code of this program with any edition of
22 the TQt library by Trolltech AS, Norway (or with modified versions
23 of TQt that use the same license as TQt), and distribute linked
24 combinations including the two. You must obey the GNU General
25 Public License in all respects for all of the code used other than
26 TQt. If you modify this file, you may extend this exception to
27 your version of the file, but you are not obligated to do so. If
28 you do not wish to do so, delete this exception statement from
29 your version.
30*/
31
32#ifdef HAVE_CONFIG_H
33#include <config.h>
34#endif
35
36#include "identitydialog.h"
37
38// other KMail headers:
39#include "signatureconfigurator.h"
40#include "xfaceconfigurator.h"
41#include "folderrequester.h"
43#include "kmfoldermgr.h"
44#include "transportmanager.h"
45#include "dictionarycombobox.h"
46#include "kleo_util.h"
47#include "kmmainwidget.h"
48#include "kmfolder.h"
49#include "templatesconfiguration.h"
50#include "templatesconfiguration_kfg.h"
51#include "simplestringlisteditor.h"
52
53// other tdepim headers:
54// libtdepim
55#include <libkpimidentities/identity.h>
56#include <libtdepim/addresseelineedit.h>
57// libkleopatra:
58#include <ui/keyrequester.h>
59#include <kleo/cryptobackendfactory.h>
60
61#include <libemailfunctions/email.h>
62
63// other KDE headers:
64#include <tdelocale.h>
65#include <tdemessagebox.h>
66#include <tdeconfig.h>
67#include <tdefileitem.h>
68#include <kurl.h>
69#include <kdebug.h>
70#include <kpushbutton.h>
71
72// TQt headers:
73#include <tqtabwidget.h>
74#include <tqlabel.h>
75#include <tqwhatsthis.h>
76#include <tqlayout.h>
77#include <tqpushbutton.h>
78#include <tqcheckbox.h>
79#include <tqcombobox.h>
80#include <tqgroupbox.h>
81#include <tqtextedit.h>
82
83// other headers:
84#include <gpgmepp/key.h>
85#include <iterator>
86#include <algorithm>
87
88using namespace KPIM;
89
90namespace KMail {
91
92 IdentityDialog::IdentityDialog( TQWidget * parent, const char * name )
93 : KDialogBase( Plain, i18n("Edit Identity"), Ok|Cancel|Help, Ok,
94 parent, name )
95 {
96 // tmp. vars:
97 TQWidget * tab;
98 TQLabel * label;
99 int row;
100 TQGridLayout * glay;
101 TQString msg;
102
103 //
104 // Tab Widget: General
105 //
106 row = -1;
107 TQVBoxLayout * vlay = new TQVBoxLayout( plainPage(), 0, spacingHint() );
108 TQTabWidget *tabWidget = new TQTabWidget( plainPage(), "config-identity-tab" );
109 vlay->addWidget( tabWidget );
110
111 tab = new TQWidget( tabWidget );
112 tabWidget->addTab( tab, i18n("&General") );
113 glay = new TQGridLayout( tab, 5, 2, marginHint(), spacingHint() );
114 glay->setRowStretch( 3, 1 );
115 glay->setColStretch( 1, 1 );
116
117 // "Name" line edit and label:
118 ++row;
119 mNameEdit = new KLineEdit( tab );
120 glay->addWidget( mNameEdit, row, 1 );
121 label = new TQLabel( mNameEdit, i18n("&Your name:"), tab );
122 glay->addWidget( label, row, 0 );
123 msg = i18n("<qt><h3>Your name</h3>"
124 "<p>This field should contain your name as you would like "
125 "it to appear in the email header that is sent out;</p>"
126 "<p>if you leave this blank your real name will not "
127 "appear, only the email address.</p></qt>");
128 TQWhatsThis::add( label, msg );
129 TQWhatsThis::add( mNameEdit, msg );
130
131 // "Organization" line edit and label:
132 ++row;
133 mOrganizationEdit = new KLineEdit( tab );
134 glay->addWidget( mOrganizationEdit, row, 1 );
135 label = new TQLabel( mOrganizationEdit, i18n("Organi&zation:"), tab );
136 glay->addWidget( label, row, 0 );
137 msg = i18n("<qt><h3>Organization</h3>"
138 "<p>This field should have the name of your organization "
139 "if you'd like it to be shown in the email header that "
140 "is sent out.</p>"
141 "<p>It is safe (and normal) to leave this blank.</p></qt>");
142 TQWhatsThis::add( label, msg );
143 TQWhatsThis::add( mOrganizationEdit, msg );
144
145 // "Email Address" line edit and label:
146 ++row;
147 mEmailEdit = new KLineEdit( tab );
148 glay->addWidget( mEmailEdit, row, 1 );
149 label = new TQLabel( mEmailEdit, i18n("&Email address:"), tab );
150 glay->addWidget( label, row, 0 );
151 msg = i18n("<qt><h3>Email address</h3>"
152 "<p>This field should have your full email address</p>"
153 "<p>This address is the primary one, used for all outgoing mail. "
154 "If you have more than one address, either create a new identity, "
155 "or add additional alias addresses in the field below.</p>"
156 "<p>If you leave this blank, or get it wrong, people "
157 "will have trouble replying to you.</p></qt>");
158 TQWhatsThis::add( label, msg );
159 TQWhatsThis::add( mEmailEdit, msg );
160
161 // "Email Aliases" string list edit and label:
162 ++row;
163 mAliasEdit = new SimpleStringListEditor( tab );
164 glay->addMultiCellWidget( mAliasEdit, row, row+1, 1, 1 );
165 label = new TQLabel( mAliasEdit, i18n("Email a&liases:"), tab );
166 glay->addWidget( label, row, 0, TQt::AlignTop );
167 msg = i18n("<qt><h3>Email aliases</h3>"
168 "<p>This field contains alias addresses that should also "
169 "be considered as belonging to this identity (as opposed "
170 "to representing a different identity).</p>"
171 "<p>Example:</p>"
172 "<table>"
173 "<tr><th>Primary address:</th><td>first.last@example.org</td></tr>"
174 "<tr><th>Aliases:</th><td>first@example.org<br>last@example.org</td></tr>"
175 "</table>"
176 "<p>Type one alias address per line.</p></qt>");
177 TQWhatsThis::add( label, msg );
178 TQWhatsThis::add( mAliasEdit, msg );
179
180 //
181 // Tab Widget: Cryptography
182 //
183 row = -1;
184 mCryptographyTab = tab = new TQWidget( tabWidget );
185 tabWidget->addTab( tab, i18n("Cryptograph&y") );
186 glay = new TQGridLayout( tab, 6, 2, marginHint(), spacingHint() );
187 glay->setColStretch( 1, 1 );
188
189 // "OpenPGP Signature Key" requester and label:
190 ++row;
191 mPGPSigningKeyRequester = new Kleo::SigningKeyRequester( false, Kleo::SigningKeyRequester::OpenPGP, tab );
192 mPGPSigningKeyRequester->dialogButton()->setText( i18n("Chang&e...") );
193 mPGPSigningKeyRequester->setDialogCaption( i18n("Your OpenPGP Signature Key") );
194 msg = i18n("Select the OpenPGP key which should be used to "
195 "digitally sign your messages.");
196 mPGPSigningKeyRequester->setDialogMessage( msg );
197
198 msg = i18n("<qt><p>The OpenPGP key you choose here will be used "
199 "to digitally sign messages. You can also use GnuPG keys.</p>"
200 "<p>You can leave this blank, but KMail will not be able "
201 "to digitally sign emails using OpenPGP; "
202 "normal mail functions will not be affected.</p>"
203 "<p>You can find out more about keys at <a>http://www.gnupg.org</a></p></qt>");
204
205 label = new TQLabel( mPGPSigningKeyRequester, i18n("OpenPGP signing key:"), tab );
206 TQWhatsThis::add( mPGPSigningKeyRequester, msg );
207 TQWhatsThis::add( label, msg );
208
209 glay->addWidget( label, row, 0 );
210 glay->addWidget( mPGPSigningKeyRequester, row, 1 );
211
212
213 // "OpenPGP Encryption Key" requester and label:
214 ++row;
215 mPGPEncryptionKeyRequester = new Kleo::EncryptionKeyRequester( false, Kleo::EncryptionKeyRequester::OpenPGP, tab );
216 mPGPEncryptionKeyRequester->dialogButton()->setText( i18n("Chang&e...") );
217 mPGPEncryptionKeyRequester->setDialogCaption( i18n("Your OpenPGP Encryption Key") );
218 msg = i18n("Select the OpenPGP key which should be used when encrypting "
219 "to yourself and for the \"Attach My Public Key\" "
220 "feature in the composer.");
221 mPGPEncryptionKeyRequester->setDialogMessage( msg );
222
223 msg = i18n("<qt><p>The OpenPGP key you choose here will be used "
224 "to encrypt messages to yourself and for the \"Attach My Public Key\" "
225 "feature in the composer. You can also use GnuPG keys.</p>"
226 "<p>You can leave this blank, but KMail will not be able "
227 "to encrypt copies of outgoing messages to you using OpenPGP; "
228 "normal mail functions will not be affected.</p>"
229 "<p>You can find out more about keys at <a>http://www.gnupg.org</a></qt>");
230 label = new TQLabel( mPGPEncryptionKeyRequester, i18n("OpenPGP encryption key:"), tab );
231 TQWhatsThis::add( mPGPEncryptionKeyRequester, msg );
232 TQWhatsThis::add( label, msg );
233
234 glay->addWidget( label, row, 0 );
235 glay->addWidget( mPGPEncryptionKeyRequester, row, 1 );
236
237
238 // "S/MIME Signature Key" requester and label:
239 ++row;
240 mSMIMESigningKeyRequester = new Kleo::SigningKeyRequester( false, Kleo::SigningKeyRequester::SMIME, tab );
241 mSMIMESigningKeyRequester->dialogButton()->setText( i18n("Chang&e...") );
242 mSMIMESigningKeyRequester->setDialogCaption( i18n("Your S/MIME Signature Certificate") );
243 msg = i18n("Select the S/MIME certificate which should be used to "
244 "digitally sign your messages.");
245 mSMIMESigningKeyRequester->setDialogMessage( msg );
246
247 msg = i18n("<qt><p>The S/MIME (X.509) certificate you choose here will be used "
248 "to digitally sign messages.</p>"
249 "<p>You can leave this blank, but KMail will not be able "
250 "to digitally sign emails using S/MIME; "
251 "normal mail functions will not be affected.</p></qt>");
252 label = new TQLabel( mSMIMESigningKeyRequester, i18n("S/MIME signing certificate:"), tab );
253 TQWhatsThis::add( mSMIMESigningKeyRequester, msg );
254 TQWhatsThis::add( label, msg );
255 glay->addWidget( label, row, 0 );
256 glay->addWidget( mSMIMESigningKeyRequester, row, 1 );
257
258 const Kleo::CryptoBackend::Protocol * smimeProtocol
259 = Kleo::CryptoBackendFactory::instance()->smime();
260
261 label->setEnabled( smimeProtocol );
262 mSMIMESigningKeyRequester->setEnabled( smimeProtocol );
263
264 // "S/MIME Encryption Key" requester and label:
265 ++row;
266 mSMIMEEncryptionKeyRequester = new Kleo::EncryptionKeyRequester( false, Kleo::EncryptionKeyRequester::SMIME, tab );
267 mSMIMEEncryptionKeyRequester->dialogButton()->setText( i18n("Chang&e...") );
268 mSMIMEEncryptionKeyRequester->setDialogCaption( i18n("Your S/MIME Encryption Certificate") );
269 msg = i18n("Select the S/MIME certificate which should be used when encrypting "
270 "to yourself and for the \"Attach My Certificate\" "
271 "feature in the composer.");
272 mSMIMEEncryptionKeyRequester->setDialogMessage( msg );
273
274 msg = i18n("<qt><p>The S/MIME certificate you choose here will be used "
275 "to encrypt messages to yourself and for the \"Attach My Certificate\" "
276 "feature in the composer.</p>"
277 "<p>You can leave this blank, but KMail will not be able "
278 "to encrypt copies of outgoing messages to you using S/MIME; "
279 "normal mail functions will not be affected.</p></qt>");
280 label = new TQLabel( mSMIMEEncryptionKeyRequester, i18n("S/MIME encryption certificate:"), tab );
281 TQWhatsThis::add( mSMIMEEncryptionKeyRequester, msg );
282 TQWhatsThis::add( label, msg );
283
284 glay->addWidget( label, row, 0 );
285 glay->addWidget( mSMIMEEncryptionKeyRequester, row, 1 );
286
287 label->setEnabled( smimeProtocol );
288 mSMIMEEncryptionKeyRequester->setEnabled( smimeProtocol );
289
290 // "Preferred Crypto Message Format" combobox and label:
291 ++row;
292 mPreferredCryptoMessageFormat = new TQComboBox( false, tab );
293 TQStringList l;
294 l << Kleo::cryptoMessageFormatToLabel( Kleo::AutoFormat )
295 << Kleo::cryptoMessageFormatToLabel( Kleo::InlineOpenPGPFormat )
296 << Kleo::cryptoMessageFormatToLabel( Kleo::OpenPGPMIMEFormat )
297 << Kleo::cryptoMessageFormatToLabel( Kleo::SMIMEFormat )
298 << Kleo::cryptoMessageFormatToLabel( Kleo::SMIMEOpaqueFormat );
299 mPreferredCryptoMessageFormat->insertStringList( l );
300 label = new TQLabel( mPreferredCryptoMessageFormat,
301 i18n("Preferred crypto message format:"), tab );
302
303 glay->addWidget( label, row, 0 );
304 glay->addWidget( mPreferredCryptoMessageFormat, row, 1 );
305
306 ++row;
307 glay->setRowStretch( row, 1 );
308
309 //
310 // Tab Widget: Advanced
311 //
312 row = -1;
313 tab = new TQWidget( tabWidget );
314 tabWidget->addTab( tab, i18n("&Advanced") );
315 glay = new TQGridLayout( tab, 8, 2, marginHint(), spacingHint() );
316 // the last (empty) row takes all the remaining space
317 glay->setRowStretch( 8-1, 1 );
318 glay->setColStretch( 1, 1 );
319
320 // "Reply-To Address" line edit and label:
321 ++row;
322 mReplyToEdit = new KPIM::AddresseeLineEdit( tab, true, "mReplyToEdit" );
323 glay->addWidget( mReplyToEdit, row, 1 );
324 label = new TQLabel ( mReplyToEdit, i18n("&Reply-To address:"), tab);
325 glay->addWidget( label , row, 0 );
326 msg = i18n("<qt><h3>Reply-To addresses</h3>"
327 "<p>This sets the <tt>Reply-to:</tt> header to contain a "
328 "different email address to the normal <tt>From:</tt> "
329 "address.</p>"
330 "<p>This can be useful when you have a group of people "
331 "working together in similar roles. For example, you "
332 "might want any emails sent to have your email in the "
333 "<tt>From:</tt> field, but any responses to go to "
334 "a group address.</p>"
335 "<p>If in doubt, leave this field blank.</p></qt>");
336 TQWhatsThis::add( label, msg );
337 TQWhatsThis::add( mReplyToEdit, msg );
338
339 // "BCC addresses" line edit and label:
340 ++row;
341 mBccEdit = new KPIM::AddresseeLineEdit( tab, true, "mBccEdit" );
342 glay->addWidget( mBccEdit, row, 1 );
343 label = new TQLabel( mBccEdit, i18n("&BCC addresses:"), tab );
344 glay->addWidget( label, row, 0 );
345 msg = i18n("<qt><h3>BCC (Blind Carbon Copy) addresses</h3>"
346 "<p>The addresses that you enter here will be added to each "
347 "outgoing mail that is sent with this identity. They will not "
348 "be visible to other recipients.</p>"
349 "<p>This is commonly used to send a copy of each sent message to "
350 "another account of yours.</p>"
351 "<p>To specify more than one address, use commas to separate "
352 "the list of BCC recipients.</p>"
353 "<p>If in doubt, leave this field blank.</p></qt>");
354 TQWhatsThis::add( label, msg );
355 TQWhatsThis::add( mBccEdit, msg );
356
357 // "Dictionary" combo box and label:
358 ++row;
359 mDictionaryCombo = new DictionaryComboBox( tab );
360 glay->addWidget( mDictionaryCombo, row, 1 );
361 glay->addWidget( new TQLabel( mDictionaryCombo, i18n("D&ictionary:"), tab ),
362 row, 0 );
363
364 // "Sent-mail Folder" combo box and label:
365 ++row;
366 mFccCombo = new FolderRequester( tab,
367 kmkernel->getKMMainWidget()->folderTree() );
368 mFccCombo->setShowOutbox( false );
369 glay->addWidget( mFccCombo, row, 1 );
370 glay->addWidget( new TQLabel( mFccCombo, i18n("Sent-mail &folder:"), tab ),
371 row, 0 );
372
373 // "Drafts Folder" combo box and label:
374 ++row;
375 mDraftsCombo = new FolderRequester( tab,
376 kmkernel->getKMMainWidget()->folderTree() );
377 mDraftsCombo->setShowOutbox( false );
378 glay->addWidget( mDraftsCombo, row, 1 );
379 glay->addWidget( new TQLabel( mDraftsCombo, i18n("&Drafts folder:"), tab ),
380 row, 0 );
381
382 // "Templates Folder" combo box and label:
383 ++row;
384 mTemplatesCombo = new FolderRequester( tab,
385 kmkernel->getKMMainWidget()->folderTree() );
386 mTemplatesCombo->setShowOutbox( false );
387 glay->addWidget( mTemplatesCombo, row, 1 );
388 glay->addWidget( new TQLabel( mTemplatesCombo, i18n("&Templates folder:"), tab ),
389 row, 0 );
390
391 // "Special transport" combobox and label:
392 ++row;
393 mTransportCheck = new TQCheckBox( i18n("Special &transport:"), tab );
394 glay->addWidget( mTransportCheck, row, 0 );
395 mTransportCombo = new TQComboBox( true, tab );
396 mTransportCombo->setEnabled( false ); // since !mTransportCheck->isChecked()
397 mTransportCombo->insertStringList( KMail::TransportManager::transportNames() );
398 glay->addWidget( mTransportCombo, row, 1 );
399 connect( mTransportCheck, TQ_SIGNAL(toggled(bool)),
400 mTransportCombo, TQ_SLOT(setEnabled(bool)) );
401
402 // the last row is a spacer
403
404 //
405 // Tab Widget: Templates
406 //
407 tab = new TQWidget( tabWidget );
408 tabWidget->addTab( tab, i18n("&Templates") );
409 vlay = new TQVBoxLayout( tab, marginHint(), spacingHint() );
410 mCustom = new TQCheckBox( i18n("&Use custom message templates"), tab );
411 vlay->addWidget( mCustom );
412 mWidget = new TemplatesConfiguration( tab , "identity-templates" );
413 mWidget->setEnabled( false );
414 vlay->addWidget( mWidget );
415 TQHBoxLayout *btns = new TQHBoxLayout( vlay, spacingHint() );
416 mCopyGlobal = new KPushButton( i18n("&Copy global templates"), tab );
417 mCopyGlobal->setEnabled( false );
418 btns->addWidget( mCopyGlobal );
419 connect( mCustom, TQ_SIGNAL( toggled( bool ) ),
420 mWidget, TQ_SLOT( setEnabled( bool ) ) );
421 connect( mCustom, TQ_SIGNAL( toggled( bool ) ),
422 mCopyGlobal, TQ_SLOT( setEnabled( bool ) ) );
423 connect( mCopyGlobal, TQ_SIGNAL(clicked()),
424 this, TQ_SLOT(slotCopyGlobal()) );
425
426 //
427 // Tab Widget: Signature
428 //
429 mSignatureConfigurator = new SignatureConfigurator( tabWidget );
430 mSignatureConfigurator->layout()->setMargin( KDialog::marginHint() );
431 tabWidget->addTab( mSignatureConfigurator, i18n("&Signature") );
432
433 mXFaceConfigurator = new XFaceConfigurator( tabWidget );
434 mXFaceConfigurator->layout()->setMargin( KDialog::marginHint() );
435 tabWidget->addTab( mXFaceConfigurator, i18n("&Picture") );
436
437 TDEConfigGroup geometry( KMKernel::config(), "Geometry" );
438 if ( geometry.hasKey( "Identity Dialog size" ) )
439 resize( geometry.readSizeEntry( "Identity Dialog size" ) );
440 mNameEdit->setFocus();
441
442 connect( tabWidget, TQ_SIGNAL(currentChanged(TQWidget*)),
443 TQ_SLOT(slotAboutToShow(TQWidget*)) );
444 }
445
446 IdentityDialog::~IdentityDialog() {
447 TDEConfigGroup geometry( KMKernel::config(), "Geometry" );
448 geometry.writeEntry( "Identity Dialog size", size() );
449 }
450
451 void IdentityDialog::slotAboutToShow( TQWidget * w ) {
452 if ( w == mCryptographyTab ) {
453 // set the configured email address as inital query of the key
454 // requesters:
455 const TQString email = mEmailEdit->text().stripWhiteSpace();
456 mPGPEncryptionKeyRequester->setInitialQuery( email );
457 mPGPSigningKeyRequester->setInitialQuery( email );
458 mSMIMEEncryptionKeyRequester->setInitialQuery( email );
459 mSMIMESigningKeyRequester->setInitialQuery( email );
460 }
461 }
462
463 void IdentityDialog::slotCopyGlobal() {
464 mWidget->loadFromGlobal();
465 }
466
467 namespace {
468 struct DoesntMatchEMailAddress {
469 explicit DoesntMatchEMailAddress( const TQString & s )
470 : email( s.stripWhiteSpace().lower() ) {}
471 bool operator()( const GpgME::Key & key ) const;
472 private:
473 bool checkForEmail( const char * email ) const;
474 static TQString extractEmail( const char * email );
475 const TQString email;
476 };
477
478 bool DoesntMatchEMailAddress::operator()( const GpgME::Key & key ) const {
479 const std::vector<GpgME::UserID> uids = key.userIDs();
480 for ( std::vector<GpgME::UserID>::const_iterator it = uids.begin() ; it != uids.end() ; ++it )
481 if ( checkForEmail( it->email() ? it->email() : it->id() ) )
482 return false;
483 return true; // note the negation!
484 }
485
486 bool DoesntMatchEMailAddress::checkForEmail( const char * e ) const {
487 const TQString em = extractEmail( e );
488 return !em.isEmpty() && email == em;
489 }
490
491 TQString DoesntMatchEMailAddress::extractEmail( const char * e ) {
492 if ( !e || !*e )
493 return TQString();
494 const TQString em = TQString::fromUtf8( e );
495 if ( e[0] == '<' )
496 return em.mid( 1, em.length() - 2 );
497 else
498 return em;
499 }
500 }
501
502bool IdentityDialog::validateAddresses( const TQString & addresses )
503{
504 TQString brokenAddress;
505 KPIM::EmailParseResult errorCode = KMMessage::isValidEmailAddressList( KMMessage::expandAliases( addresses ), brokenAddress );
506 if ( !( errorCode == KPIM::AddressOk || errorCode == KPIM::AddressEmpty ) ) {
507 TQString errorMsg( "<qt><p><b>" + brokenAddress +
508 "</b></p><p>" + KPIM::emailParseResultToString( errorCode ) +
509 "</p></qt>" );
510 KMessageBox::sorry( this, errorMsg, i18n("Invalid Email Address") );
511 return false;
512 }
513 return true;
514}
515
516void IdentityDialog::slotOk() {
517 const TQString email = mEmailEdit->text().stripWhiteSpace();
518
519 // Validate email addresses
520 if ( !isValidSimpleEmailAddress( email )) {
521 TQString errorMsg( simpleEmailAddressErrorMsg());
522 KMessageBox::sorry( this, errorMsg, i18n("Invalid Email Address") );
523 return;
524 }
525
526 const TQStringList aliases = mAliasEdit->stringList();
527 for ( TQStringList::const_iterator it = aliases.begin(), end = aliases.end() ; it != end ; ++it ) {
528 if ( !isValidSimpleEmailAddress( *it ) ) {
529 TQString errorMsg( simpleEmailAddressErrorMsg());
530 KMessageBox::sorry( this, errorMsg, i18n("Invalid Email Alias \"%1\"").arg( *it ) );
531 return;
532 }
533 }
534
535 if ( !validateAddresses( mReplyToEdit->text().stripWhiteSpace() ) ) {
536 return;
537 }
538
539 if ( !validateAddresses( mBccEdit->text().stripWhiteSpace() ) ) {
540 return;
541 }
542
543 const std::vector<GpgME::Key> & pgpSigningKeys = mPGPSigningKeyRequester->keys();
544 const std::vector<GpgME::Key> & pgpEncryptionKeys = mPGPEncryptionKeyRequester->keys();
545 const std::vector<GpgME::Key> & smimeSigningKeys = mSMIMESigningKeyRequester->keys();
546 const std::vector<GpgME::Key> & smimeEncryptionKeys = mSMIMEEncryptionKeyRequester->keys();
547 TQString msg;
548 bool err = false;
549 if ( std::find_if( pgpSigningKeys.begin(), pgpSigningKeys.end(),
550 DoesntMatchEMailAddress( email ) ) != pgpSigningKeys.end() ) {
551 msg = i18n("One of the configured OpenPGP signing keys does not contain "
552 "any user ID with the configured email address for this "
553 "identity (%1).\n"
554 "This might result in warning messages on the receiving side "
555 "when trying to verify signatures made with this configuration.");
556 err = true;
557 }
558 else if ( std::find_if( pgpEncryptionKeys.begin(), pgpEncryptionKeys.end(),
559 DoesntMatchEMailAddress( email ) ) != pgpEncryptionKeys.end() ) {
560 msg = i18n("One of the configured OpenPGP encryption keys does not contain "
561 "any user ID with the configured email address for this "
562 "identity (%1).");
563 err = true;
564 }
565 else if ( std::find_if( smimeSigningKeys.begin(), smimeSigningKeys.end(),
566 DoesntMatchEMailAddress( email ) ) != smimeSigningKeys.end() ) {
567 msg = i18n("One of the configured S/MIME signing certificates does not contain "
568 "the configured email address for this "
569 "identity (%1).\n"
570 "This might result in warning messages on the receiving side "
571 "when trying to verify signatures made with this configuration.");
572 err = true;
573 }
574 else if ( std::find_if( smimeEncryptionKeys.begin(), smimeEncryptionKeys.end(),
575 DoesntMatchEMailAddress( email ) ) != smimeEncryptionKeys.end() ) {
576 msg = i18n("One of the configured S/MIME encryption certificates does not contain "
577 "the configured email address for this "
578 "identity (%1).");
579 err = true;
580 }
581
582 if ( err )
583 if ( KMessageBox::warningContinueCancel( this, msg.arg( email ),
584 i18n("Email Address Not Found in Key/Certificates"),
585 KStdGuiItem::cont(), "warn_email_not_in_certificate" )
586 != KMessageBox::Continue)
587 return;
588
589
590 if ( mSignatureConfigurator->isSignatureEnabled() &&
591 mSignatureConfigurator->signatureType()==Signature::FromFile ) {
592 KURL url( mSignatureConfigurator->fileURL() );
593 KFileItem signatureFile( KFileItem::Unknown, KFileItem::Unknown, url );
594 if ( !signatureFile.isFile() || !signatureFile.isReadable() || !signatureFile.isLocalFile() ) {
595 KMessageBox::error( this, i18n( "The signature file is not valid" ) );
596 return;
597 }
598 }
599
600 return KDialogBase::slotOk();
601 }
602
603 bool IdentityDialog::checkFolderExists( const TQString & folderID,
604 const TQString & msg ) {
605 KMFolder * folder = kmkernel->findFolderById( folderID );
606 if ( !folder ) {
607 KMessageBox::sorry( this, msg );
608 return false;
609 }
610 return true;
611 }
612
613 void IdentityDialog::setIdentity( KPIM::Identity & ident ) {
614
615 setCaption( i18n("Edit Identity \"%1\"").arg( ident.identityName() ) );
616
617 // "General" tab:
618 mNameEdit->setText( ident.fullName() );
619 mOrganizationEdit->setText( ident.organization() );
620 mEmailEdit->setText( ident.primaryEmailAddress() );
621 mAliasEdit->setStringList( ident.emailAliases() );
622
623 // "Cryptography" tab:
624 mPGPSigningKeyRequester->setFingerprint( ident.pgpSigningKey() );
625 mPGPEncryptionKeyRequester->setFingerprint( ident.pgpEncryptionKey() );
626 mSMIMESigningKeyRequester->setFingerprint( ident.smimeSigningKey() );
627 mSMIMEEncryptionKeyRequester->setFingerprint( ident.smimeEncryptionKey() );
628 mPreferredCryptoMessageFormat->setCurrentItem( format2cb( ident.preferredCryptoMessageFormat() ) );
629
630 // "Advanced" tab:
631 mReplyToEdit->setText( ident.replyToAddr() );
632 mBccEdit->setText( ident.bcc() );
633 mTransportCheck->setChecked( !ident.transport().isEmpty() );
634 mTransportCombo->setEditText( ident.transport() );
635 mTransportCombo->setEnabled( !ident.transport().isEmpty() );
636 mDictionaryCombo->setCurrentByDictionary( ident.dictionary() );
637
638 if ( ident.fcc().isEmpty() ||
639 !checkFolderExists( ident.fcc(),
640 i18n("The custom sent-mail folder for identity "
641 "\"%1\" does not exist (anymore); "
642 "therefore, the default sent-mail folder "
643 "will be used.")
644 .arg( ident.identityName() ) ) )
645 mFccCombo->setFolder( kmkernel->sentFolder() );
646 else
647 mFccCombo->setFolder( ident.fcc() );
648
649 if ( ident.drafts().isEmpty() ||
650 !checkFolderExists( ident.drafts(),
651 i18n("The custom drafts folder for identity "
652 "\"%1\" does not exist (anymore); "
653 "therefore, the default drafts folder "
654 "will be used.")
655 .arg( ident.identityName() ) ) )
656 mDraftsCombo->setFolder( kmkernel->draftsFolder() );
657 else
658 mDraftsCombo->setFolder( ident.drafts() );
659
660 if ( ident.templates().isEmpty() ||
661 !checkFolderExists( ident.templates(),
662 i18n("The custom templates folder for identity "
663 "\"%1\" does not exist (anymore); "
664 "therefore, the default templates folder "
665 "will be used.")
666 .arg( ident.identityName() ) ) )
667 mTemplatesCombo->setFolder( kmkernel->templatesFolder() );
668 else
669 mTemplatesCombo->setFolder( ident.templates() );
670
671 // "Templates" tab:
672 uint identity = ident.uoid();
673 TQString iid = TQString("IDENTITY_%1").arg( identity );
674 Templates t( iid );
675 mCustom->setChecked(t.useCustomTemplates());
676 mWidget->loadFromIdentity( identity );
677
678 // "Signature" tab:
679 mSignatureConfigurator->setSignature( ident.signature() );
680 mXFaceConfigurator->setXFace( ident.xface() );
681 mXFaceConfigurator->setXFaceEnabled( ident.isXFaceEnabled() );
682 }
683
684 void IdentityDialog::updateIdentity( KPIM::Identity & ident ) {
685 // "General" tab:
686 ident.setFullName( mNameEdit->text() );
687 ident.setOrganization( mOrganizationEdit->text() );
688 TQString email = mEmailEdit->text();
689 ident.setPrimaryEmailAddress( email );
690 const TQStringList aliases = mAliasEdit->stringList();
691 ident.setEmailAliases( aliases );
692 // "Cryptography" tab:
693 ident.setPGPSigningKey( mPGPSigningKeyRequester->fingerprint().latin1() );
694 ident.setPGPEncryptionKey( mPGPEncryptionKeyRequester->fingerprint().latin1() );
695 ident.setSMIMESigningKey( mSMIMESigningKeyRequester->fingerprint().latin1() );
696 ident.setSMIMEEncryptionKey( mSMIMEEncryptionKeyRequester->fingerprint().latin1() );
697 ident.setPreferredCryptoMessageFormat( cb2format( mPreferredCryptoMessageFormat->currentItem() ) );
698 // "Advanced" tab:
699 ident.setReplyToAddr( mReplyToEdit->text() );
700 ident.setBcc( mBccEdit->text() );
701 ident.setTransport( ( mTransportCheck->isChecked() ) ?
702 mTransportCombo->currentText() : TQString() );
703 ident.setDictionary( mDictionaryCombo->currentDictionary() );
704 ident.setFcc( mFccCombo->folder() ?
705 mFccCombo->folder()->idString() : TQString() );
706 ident.setDrafts( mDraftsCombo->folder() ?
707 mDraftsCombo->folder()->idString() : TQString() );
708 ident.setTemplates( mTemplatesCombo->folder() ?
709 mTemplatesCombo->folder()->idString() : TQString() );
710 // "Templates" tab:
711 uint identity = ident.uoid();
712 TQString iid = TQString("IDENTITY_%1").arg( identity );
713 Templates t( iid );
714 kdDebug() << "use custom templates for identity " << identity << ": " << mCustom->isChecked() << endl;
715 t.setUseCustomTemplates(mCustom->isChecked());
716 t.writeConfig();
717 mWidget->saveToIdentity( identity );
718 // "Signature" tab:
719 ident.setSignature( mSignatureConfigurator->signature() );
720 ident.setXFace( mXFaceConfigurator->xface() );
721 ident.setXFaceEnabled( mXFaceConfigurator->isXFaceEnabled() );
722 }
723
724 void IdentityDialog::slotUpdateTransportCombo( const TQStringList & sl ) {
725 // save old setting:
726 TQString content = mTransportCombo->currentText();
727 // update combo box:
728 mTransportCombo->clear();
729 mTransportCombo->insertStringList( sl );
730 // restore saved setting:
731 mTransportCombo->setEditText( content );
732 }
733
734}
735
736#include "identitydialog.moc"
Mail folder.
Definition: kmfolder.h:69
static KPIM::EmailParseResult isValidEmailAddressList(const TQString &aStr, TQString &brokenAddress)
Validate a list of email addresses, and also allow aliases and distribution lists to be expanded befo...
Definition: kmmessage.cpp:273
static TQString expandAliases(const TQString &recipients)
Expands aliases (distribution lists and nick names) and appends a domain part to all email addresses ...
Definition: kmmessage.cpp:3953
A widget that contains a KLineEdit which shows the current folder and a button that fires a KMFolderS...
static TQStringList transportNames()
Returns the list for transport names.
@ Ok
The user rights/ACL have been fetched from the server sucessfully.
Definition: acljobs.h:66
folderdiaquotatab.h
Definition: aboutdata.cpp:40