[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/kdepim/enterprise/kdepim
From:       Marc Mutz <mutz () kde ! org>
Date:       2010-05-04 12:25:07
Message-ID: 20100504122507.35C68AC8AB () svn ! kde ! org
[Download RAW message or body]

SVN commit 1122656 by mutz:

libkpimidentities: add email aliases to Identity; use them in KMail, KOrg, wizards/

With this patch, KMail allows an identity to have arbitrarily many email 
aliases. Aliases are email addresses that are considered representing the 
identity, but that will not be used for outgoing messages.

The immediate problem this is fixing is that hitting 'A' on a message with 
an old (=alias) address includes that (old/alias) address in the list of To's.

 M  +2 -2      kmail/accountwizard.cpp  
 M  +1 -1      kmail/callback.cpp  
 M  +48 -5     kmail/identitydialog.cpp  
 M  +2 -0      kmail/identitydialog.h  
 M  +2 -2      kmail/kmmessage.cpp  
 M  +2 -2      kmail/kmsender.cpp  
 M  +5 -3      kmail/vacation.cpp  
 M  +4 -1      korganizer/koprefs.cpp  
 M  +24 -2     libkpimidentities/identity.cpp  
 M  +14 -2     libkpimidentities/identity.h  
 M  +8 -10     libkpimidentities/identitymanager.cpp  
 M  +1 -1      wizards/kmailchanges.cpp  


--- branches/kdepim/enterprise/kdepim/kmail/accountwizard.cpp #1122655:1122656
@@ -146,7 +146,7 @@
       const KPIM::Identity &identity = manager->defaultIdentity();
 
       mRealName->setText( identity.fullName() );
-      mEMailAddress->setText( identity.emailAddr() );
+      mEMailAddress->setText( identity.primaryEmailAddress() );
       mOrganization->setText( identity.organization() );
     }
   } else if ( page == mLoginInformationPage ) {
@@ -356,7 +356,7 @@
   KPIM::Identity &identity = manager->modifyIdentityForUoid( \
manager->defaultIdentity().uoid() );  
   identity.setFullName( mRealName->text() );
-  identity.setEmailAddr( mEMailAddress->text() );
+  identity.setPrimaryEmailAddress( mEMailAddress->text() );
   identity.setOrganization( mOrganization->text() );
 
   manager->commit();
--- branches/kdepim/enterprise/kdepim/kmail/callback.cpp #1122655:1122656
@@ -226,7 +226,7 @@
     }
 
     // select default identity by default
-    const QString defaultAddr = \
kmkernel->identityManager()->defaultIdentity().emailAddr(); +    const QString \
defaultAddr = kmkernel->identityManager()->defaultIdentity().primaryEmailAddress();  \
const int defaultIndex = QMAX( 0, addrs.findIndex( defaultAddr ) );  
     mReceiver =
--- branches/kdepim/enterprise/kdepim/kmail/identitydialog.cpp #1122655:1122656
@@ -76,6 +76,8 @@
 #include <qpushbutton.h>
 #include <qcheckbox.h>
 #include <qcombobox.h>
+#include <qgroupbox.h>
+#include <qtextedit.h>
 
 // other headers:
 #include <gpgmepp/key.h>
@@ -107,7 +109,7 @@
 
     tab = new QWidget( tabWidget );
     tabWidget->addTab( tab, i18n("&General") );
-    glay = new QGridLayout( tab, 4, 2, marginHint(), spacingHint() );
+    glay = new QGridLayout( tab, 5, 2, marginHint(), spacingHint() );
     glay->setRowStretch( 3, 1 );
     glay->setColStretch( 1, 1 );
 
@@ -140,19 +142,48 @@
     QWhatsThis::add( mOrganizationEdit, msg );
 
     // "Email Address" line edit and label:
-    // (row 3: spacer)
     ++row;
     mEmailEdit = new KLineEdit( tab );
     glay->addWidget( mEmailEdit, row, 1 );
     label = new QLabel( mEmailEdit, i18n("&Email address:"), tab );
     glay->addWidget( label, row, 0 );
     msg = i18n("<qt><h3>Email address</h3>"
-               "<p>This field should have your full email address.</p>"
+               "<p>This field should have your full email address</p>"
+               "<p>This address is the primary one, used for all outgoing mail. "
+               "If you have more than one address, either create a new identiy, "
+               "or add additional alias addresses in the field below.</p>"
                "<p>If you leave this blank, or get it wrong, people "
                "will have trouble replying to you.</p></qt>");
     QWhatsThis::add( label, msg );
     QWhatsThis::add( mEmailEdit, msg );
 
+    // "Email Aliases" text edit and label:
+    ++row;
+    mAliasEdit = new QTextEdit( tab );
+    mAliasEdit->setWordWrap( QTextEdit::NoWrap );
+    mAliasEdit->setTextFormat( Qt::PlainText );
+    glay->addWidget( mAliasEdit, row, 1 );
+    label = new QLabel( mAliasEdit, i18n("Email a&liases:"), tab );
+    glay->addWidget( label, row, 0, Qt::AlignTop );
+    msg = i18n("<qt><h3>Email aliases</h3>"
+               "<p>This field contains alias addresses that should also "
+               "be considered as belonging to this identity (as opposed "
+               "to representing a different identity).</p>"
+               "<p>Example:</p>"
+               "<table>"
+               "<tr><th>Primary address:</th><td>first.last@example.org</td></tr>"
+               "<tr><th>Aliases:</th><td>first@example.org<br>last@example.org</td></tr>"
 +               "</table>"
+               "<p>Type one alias address per line.</p></qt>");
+    QWhatsThis::add( label, msg );
+    QWhatsThis::add( mAliasEdit, msg );
+
+    // "(one address per line)":
+    ++row;
+    label = new QLabel( i18n("(enter one alias per line)"), tab );
+    glay->addWidget( label, row, 1 );
+    QWhatsThis::add( label, msg );
+
     //
     // Tab Widget: Cryptography
     //
@@ -499,6 +530,15 @@
       return;
     }
 
+    const QStringList aliases = QStringList::split( '\n', mAliasEdit->text() );
+    for ( QStringList::const_iterator it = aliases.begin(), end = aliases.end() ; it \
!= end ; ++it ) { +      if ( !isValidSimpleEmailAddress( *it ) ) {
+        QString errorMsg( simpleEmailAddressErrorMsg());
+        KMessageBox::sorry( this, errorMsg, i18n("Invalid Email Alias \"%1\"").arg( \
*it ) ); +        return;
+      }
+    }
+
     if ( !validateAddresses( mReplyToEdit->text().stripWhiteSpace() ) ) {
       return;
     }
@@ -584,7 +624,8 @@
     // "General" tab:
     mNameEdit->setText( ident.fullName() );
     mOrganizationEdit->setText( ident.organization() );
-    mEmailEdit->setText( ident.emailAddr() );
+    mEmailEdit->setText( ident.primaryEmailAddress() );
+    mAliasEdit->setText( ident.emailAliases().join("\n") );
 
     // "Cryptography" tab:
     mPGPSigningKeyRequester->setFingerprint( ident.pgpSigningKey() );
@@ -652,7 +693,9 @@
     ident.setFullName( mNameEdit->text() );
     ident.setOrganization( mOrganizationEdit->text() );
     QString email = mEmailEdit->text();
-    ident.setEmailAddr( email );
+    ident.setPrimaryEmailAddress( email );
+    const QStringList aliases = QStringList::split( '\n', mAliasEdit->text() );
+    ident.setEmailAliases( aliases );
     // "Cryptography" tab:
     ident.setPGPSigningKey( mPGPSigningKeyRequester->fingerprint().latin1() );
     ident.setPGPEncryptionKey( mPGPEncryptionKeyRequester->fingerprint().latin1() );
--- branches/kdepim/enterprise/kdepim/kmail/identitydialog.h #1122655:1122656
@@ -40,6 +40,7 @@
 class QComboBox;
 class QString;
 class QStringList;
+class QTextEdit;
 class TemplatesConfiguration;
 class KPushButton;
 namespace Kleo {
@@ -87,6 +88,7 @@
     QLineEdit                    *mNameEdit;
     QLineEdit                    *mOrganizationEdit;
     QLineEdit                    *mEmailEdit;
+    QTextEdit                    *mAliasEdit;
     // "cryptography" tab:
     QWidget                      *mCryptographyTab;
     Kleo::SigningKeyRequester    *mPGPSigningKeyRequester;
--- branches/kdepim/enterprise/kdepim/kmail/kmmessage.cpp #1122655:1122656
@@ -1143,12 +1143,12 @@
   QString strByWayOf = QString("%1 (by way of %2 <%3>)")
     .arg( from() )
     .arg( ident.fullName() )
-    .arg( ident.emailAddr() );
+    .arg( ident.primaryEmailAddress() );
 
   // Resent-From: content
   QString strFrom = QString("%1 <%2>")
     .arg( ident.fullName() )
-    .arg( ident.emailAddr() );
+    .arg( ident.primaryEmailAddress() );
 
   // format the current date to be used in Resent-Date:
   QString origDate = msg->headerField( "Date" );
--- branches/kdepim/enterprise/kdepim/kmail/kmsender.cpp #1122655:1122656
@@ -422,10 +422,10 @@
     // empty
     const KPIM::Identity & id = kmkernel->identityManager()
       ->identityForUoidOrDefault( mCurrentMsg->headerField( "X-KMail-Identity" \
                ).stripWhiteSpace().toUInt() );
-    if ( !id.emailAddr().isEmpty() ) {
+    if ( !id.primaryEmailAddress().isEmpty() ) {
       mCurrentMsg->setFrom( id.fullEmailAddr() );
     }
-    else if ( !kmkernel->identityManager()->defaultIdentity().emailAddr().isEmpty() \
) { +    else if ( !kmkernel->identityManager()->defaultIdentity().primaryEmailAddress().isEmpty() \
                ) {
       mCurrentMsg->setFrom( \
kmkernel->identityManager()->defaultIdentity().fullEmailAddr() );  }
     else {
--- branches/kdepim/enterprise/kdepim/kmail/vacation.cpp #1122655:1122656
@@ -583,9 +583,11 @@
   QStringList Vacation::defaultMailAliases() {
     QStringList sl;
     for ( KPIM::IdentityManager::ConstIterator it = \
                kmkernel->identityManager()->begin() ;
-	  it != kmkernel->identityManager()->end() ; ++it )
-      if ( !(*it).emailAddr().isEmpty() )
-	sl.push_back( (*it).emailAddr() );
+	  it != kmkernel->identityManager()->end() ; ++it ) {
+      if ( !(*it).primaryEmailAddress().isEmpty() )
+	sl.push_back( (*it).primaryEmailAddress() );
+      sl += (*it).emailAliases();
+    }
     return sl;
   }
 
--- branches/kdepim/enterprise/kdepim/korganizer/koprefs.cpp #1122655:1122656
@@ -415,8 +415,11 @@
 
   for ( KPIM::IdentityManager::ConstIterator it = \
KOCore::self()->identityManager()->begin();  it != \
                KOCore::self()->identityManager()->end(); ++it ) {
-    if ( email == (*it).emailAddr() )
+    if ( email == (*it).primaryEmailAddress() )
       return true;
+    const QStringList & aliases = (*it).emailAliases();
+    if ( aliases.find( email ) != aliases.end() )
+        return true;
   }
 
   if ( mAdditionalMails.find( email ) != mAdditionalMails.end() )
--- branches/kdepim/enterprise/kdepim/libkpimidentities/identity.cpp #1122655:1122656
@@ -236,6 +236,7 @@
 
 bool Identity::isNull() const {
   return mIdentity.isEmpty() && mFullName.isEmpty() && mEmailAddr.isEmpty() &&
+    mEmailAliases.empty() &&
     mOrganization.isEmpty() && mReplyToAddr.isEmpty() && mBcc.isEmpty() &&
     mVCardFile.isEmpty() &&
     mFcc.isEmpty() && mDrafts.isEmpty() && mTemplates.isEmpty() &&
@@ -251,6 +252,7 @@
   bool same = mUoid == other.mUoid &&
       mIdentity == other.mIdentity && mFullName == other.mFullName &&
       mEmailAddr == other.mEmailAddr && mOrganization == other.mOrganization &&
+      mEmailAliases == other.mEmailAliases &&
       mReplyToAddr == other.mReplyToAddr && mBcc == other.mBcc &&
       mVCardFile == other.mVCardFile &&
       mFcc == other.mFcc &&
@@ -271,6 +273,7 @@
   if ( mIdentity != other.mIdentity ) kdDebug() << "mIdentity differs : " << \
mIdentity << " != " << other.mIdentity << endl;  if ( mFullName != other.mFullName ) \
kdDebug() << "mFullName differs : " << mFullName << " != " << other.mFullName << \
endl;  if ( mEmailAddr != other.mEmailAddr ) kdDebug() << "mEmailAddr differs : " << \
mEmailAddr << " != " << other.mEmailAddr << endl; +  if ( mEmailAliases != \
other.mEmailAliases ) kdDebug() << "mEmailAliases differs : " << \
mEmailAliases.join(";") << " != " << other.mEmailAliases.join(";") << endl;  if ( \
mOrganization != other.mOrganization ) kdDebug() << "mOrganization differs : " << \
mOrganization << " != " << other.mOrganization << endl;  if ( mReplyToAddr != \
other.mReplyToAddr ) kdDebug() << "mReplyToAddr differs : " << mReplyToAddr << " != " \
<< other.mReplyToAddr << endl;  if ( mBcc != other.mBcc ) kdDebug() << "mBcc differs \
: " << mBcc << " != " << other.mBcc << endl; @@ -320,6 +323,7 @@
   mIdentity = config->readEntry("Identity");
   mFullName = config->readEntry("Name");
   mEmailAddr = config->readEntry("Email Address");
+  mEmailAliases = config->readListEntry("Email Aliases");
   mVCardFile = config->readPathEntry("VCardFile");
   mOrganization = config->readEntry("Organization");
   mPGPSigningKey = config->readEntry("PGP Signing Key").latin1();
@@ -362,6 +366,7 @@
   config->writeEntry("SMIME Encryption Key", mSMIMEEncryptionKey.data());
   config->writeEntry("Preferred Crypto Message Format", \
Kleo::cryptoMessageFormatToString( mPreferredCryptoMessageFormat ) );  \
config->writeEntry("Email Address", mEmailAddr); +  config->writeEntry("Email \
Aliases", mEmailAliases);  config->writeEntry("Reply-To Address", mReplyToAddr);
   config->writeEntry("Bcc", mBcc);
   config->writePathEntry("VCardFile", mVCardFile);
@@ -385,7 +390,8 @@
 		<< i.pgpEncryptionKey()
 		<< i.smimeSigningKey()
 		<< i.smimeEncryptionKey()
-		<< i.emailAddr()
+		<< i.primaryEmailAddress()
+		<< i.emailAliases()
 		<< i.replyToAddr()
 		<< i.bcc()
 		<< i.vCardFile()
@@ -411,6 +417,7 @@
 		>> i.mSMIMESigningKey
 		>> i.mSMIMEEncryptionKey
 		>> i.mEmailAddr
+		>> i.mEmailAliases
 		>> i.mReplyToAddr
 		>> i.mBcc
 		>> i.mVCardFile
@@ -484,12 +491,27 @@
 }
 
 //-----------------------------------------------------------------------------
-void Identity::setEmailAddr(const QString &str)
+void Identity::setPrimaryEmailAddress( const QString & str )
 {
   mEmailAddr = str;
 }
 
+void Identity::setEmailAliases( const QStringList & list )
+{
+  mEmailAliases = list;
+}
 
+bool Identity::matchesEmailAddress( const QString & addr ) const
+{
+  const QString lower = addr.lower();
+  if ( lower == mEmailAddr.lower() )
+    return true;
+  for ( QStringList::const_iterator it = mEmailAliases.begin(), end = \
mEmailAliases.end() ; it != end ; ++it ) +    if ( (*it).lower() == lower )
+      return true;
+  return false;
+}
+
 //-----------------------------------------------------------------------------
 void Identity::setVCardFile(const QString &str)
 {
--- branches/kdepim/enterprise/kdepim/libkpimidentities/identity.h #1122655:1122656
@@ -206,9 +206,20 @@
   void setPreferredCryptoMessageFormat( Kleo::CryptoMessageFormat format ) { \
mPreferredCryptoMessageFormat = format; }  
   /** email address (without the user name - only name\@host) */
-  QString emailAddr() const { return mEmailAddr; }
-  void setEmailAddr(const QString&);
+  KDE_DEPRECATED QString emailAddr() const { return primaryEmailAddress(); }
+  KDE_DEPRECATED void setEmailAddr( const QString & email ) { \
setPrimaryEmailAddress( email ); }  
+  /** primary email address (without the user name - only name\@host).
+      The primary email address is used for all outgoing mail. */
+  QString primaryEmailAddress() const { return mEmailAddr; }
+  void setPrimaryEmailAddress( const QString & email );
+
+  /** email address aliases */
+  const QStringList & emailAliases() const { return mEmailAliases; }
+  void setEmailAliases( const QStringList & );
+
+  bool matchesEmailAddress( const QString & addr ) const;
+
   /** vCard to attach to outgoing emails */
   QString vCardFile() const { return mVCardFile; }
   void setVCardFile(const QString&);
@@ -295,6 +306,7 @@
   // and operator>> accordingly:
   uint mUoid;
   QString mIdentity, mFullName, mEmailAddr, mOrganization;
+  QStringList mEmailAliases;
   QString mReplyToAddr;
   QString mBcc;
   QString mVCardFile;
--- branches/kdepim/enterprise/kdepim/libkpimidentities/identitymanager.cpp \
#1122655:1122656 @@ -211,7 +211,7 @@
       // Also write the default identity to emailsettings
       KEMailSettings es;
       es.setSetting( KEMailSettings::RealName, (*it).fullName() );
-      es.setSetting( KEMailSettings::EmailAddress, (*it).emailAddr() );
+      es.setSetting( KEMailSettings::EmailAddress, (*it).primaryEmailAddress() );
       es.setSetting( KEMailSettings::Organization, (*it).organization() );
       es.setSetting( KEMailSettings::ReplyToAddress, (*it).replyToAddr() );
     }
@@ -304,16 +304,14 @@
 
 const Identity & IdentityManager::identityForAddress( const QString & addresses ) \
const  {
-  QStringList addressList = KPIM::splitEmailAddrList( addresses );
-  for ( ConstIterator it = begin() ; it != end() ; ++it ) {
+  const QStringList addressList = KPIM::splitEmailAddrList( addresses );
     for( QStringList::ConstIterator addrIt = addressList.begin();
          addrIt != addressList.end(); ++addrIt ) {
-      // I use QString::utf8() instead of QString::latin1() because I want
-      // a QCString and not a char*. It doesn't matter because emailAddr()
-      // returns a 7-bit string.
-      if( (*it).emailAddr().lower() ==
-          KPIM::getEmailAddress( *addrIt ).lower() ) {
-        return (*it);
+    const QString addr = KPIM::getEmailAddress( *addrIt ).lower();
+    for ( ConstIterator it = begin() ; it != end() ; ++it ) {
+      const Identity & id = *it;
+      if ( id.matchesEmailAddress( addr ) ) {
+        return id;
       }
     }
   }
@@ -499,7 +497,7 @@
 {
   QStringList lst;
   for ( ConstIterator it = begin() ; it != end() ; ++it ) {
-    lst << (*it).emailAddr();
+    lst << (*it).primaryEmailAddress();
   }
   return lst;
 }
--- branches/kdepim/enterprise/kdepim/wizards/kmailchanges.cpp #1122655:1122656
@@ -296,7 +296,7 @@
 
     KPIM::Identity& identity = identityManager.newFromScratch( accountName );
     identity.setFullName( mRealName );
-    identity.setEmailAddr( mEmail );
+    identity.setPrimaryEmailAddress( mEmail );
     identityManager.commit();
   }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic