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

List:       kde-commits
Subject:    kdepim/kmail
From:       Matt Douhan <matt () fruitsalad ! org>
Date:       2005-04-07 20:57:36
Message-ID: 20050407205736.EFE4363E () office ! kde ! org
[Download RAW message or body]

CVS commit by mdouhan: 

Refactor the address validation to use a helper method

Make it static he said and the nightmare began, 1 hour later it compiled.

Make it file static they said and the walls came crashing down

the deal is, I make it file static when someone explains to me how that works


  M +20 -30    kmcomposewin.cpp   1.927
  M +5 -0      kmcomposewin.h   1.276


--- kdepim/kmail/kmcomposewin.cpp  #1.926:1.927
@@ -3589,4 +3589,18 @@ void KMComposeWin::slotContinuePrint( bo
 }
 
+//----------------------------------------------------------------------------
+bool KMComposeWin::validateAddresses( QWidget * parent, const QString & addresses )
+{
+  QString brokenAddress;
+  KPIM::EmailParseResult errorCode = KMMessage::isValidEmailAddressList( \
KMMessage::expandAliases( addresses ), brokenAddress ); +  if ( !( errorCode == \
KPIM::AddressOk || errorCode == KPIM::AddressEmpty ) ) { +    QString errorMsg( \
"<qt><p><b>" + brokenAddress + +                      "</b></p><p>" + \
KPIM::emailParseResultToString( errorCode ) + +                      "</p></qt>" );
+    KMessageBox::sorry( parent, errorMsg, i18n("Invalid Email Address") );
+    return false;
+  }
+  return true;
+}
 
 //----------------------------------------------------------------------------
@@ -3621,39 +3635,15 @@ void KMComposeWin::doSend(int aSendNow, 
 
     // Validate the To:, CC: and BCC fields
-    if ( !to().isEmpty() ) {
-      QString brokenAddress;
-      KPIM::EmailParseResult errorCode = KMMessage::isValidEmailAddressList( \
                KMMessage::expandAliases( to()), brokenAddress );
-      if ( errorCode != KPIM::AddressOk ) {
-        QString errorMsg( "<qt><p><b>" + brokenAddress +
-                          "</b></p><p>" + KPIM::emailParseResultToString( errorCode \
                ) +
-                          "</p></qt>" );
-        KMessageBox::sorry( this, errorMsg, i18n("Invalid Email Address") );
+    if ( !validateAddresses( this, to().stripWhiteSpace() ) ) {
         return;
       }
-    }
 
-    if ( !cc().isEmpty() ) {
-      QString brokenAddress;
-      KPIM::EmailParseResult errorCode = KMMessage::isValidEmailAddressList( \
                KMMessage::expandAliases( cc()), brokenAddress);
-      if ( errorCode != KPIM::AddressOk ) {
-        QString errorMsg( "<qt><p><b>" + brokenAddress +
-                          "</b></p><p>" + KPIM::emailParseResultToString( errorCode \
                ) +
-                          "</p></qt>" );
-        KMessageBox::sorry( this, errorMsg, i18n("Invalid Email Address") );
+    if ( !validateAddresses( this, cc().stripWhiteSpace() ) ) {
         return;
       }
-    }
 
-    if ( !bcc().isEmpty() ) {
-      QString brokenAddress;
-      KPIM::EmailParseResult errorCode = KMMessage::isValidEmailAddressList( \
                KMMessage::expandAliases( bcc()), brokenAddress);
-        if ( errorCode != KPIM::AddressOk ) {
-          QString errorMsg( "<qt><p><b>" + brokenAddress +
-                          "</b></p><p>" + KPIM::emailParseResultToString( errorCode \
                ) +
-                          "</p></qt>" );
-        KMessageBox::sorry( this, errorMsg, i18n("Invalid Email Address") );
+    if ( !validateAddresses( this, bcc().stripWhiteSpace() ) ) {
         return;
       }
-    }
 
     if (subject().isEmpty())

--- kdepim/kmail/kmcomposewin.h  #1.275:1.276
@@ -802,4 +802,9 @@ private:
   void cleanupAutoSave();
 
+  /**
+   * Validate email addresses
+   */
+  static bool KMComposeWin::validateAddresses( QWidget * parent, const QString & \
addresses ); +
 protected slots:
    /**


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

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