Update of /cvsroot/mahogany/M/src/mail
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv7889/src/mail

Modified Files:
        ASMailFolder.cpp Address.cpp HeaderInfoImpl.cpp MailFolder.cpp 
        Message.cpp SendMessageCC.cpp 
Log Message:
removed deprecated address-parsing functions from Message and replaced them 
with Address class methods

Index: ASMailFolder.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/mail/ASMailFolder.cpp,v
retrieving revision 1.75
retrieving revision 1.76
diff -b -u -2 -r1.75 -r1.76
--- ASMailFolder.cpp    16 Jan 2006 20:32:28 -0000      1.75
+++ ASMailFolder.cpp    23 Jun 2006 23:27:31 -0000      1.76
@@ -407,10 +407,9 @@
    ~MT_AppendMessage()
       {
-         if(m_Message) m_Message->DecRef();
+         m_Message->DecRef();
       }
    virtual void WorkFunction(void)
       {
-         int rc = m_Message ?
-            m_MailFolder->AppendMessage(*m_Message)
+         int rc = m_Message ? m_MailFolder->AppendMessage(*m_Message)
             : m_MailFolder->AppendMessage(m_MsgString);
          SendEvent(ASMailFolder::ResultInt::
@@ -775,4 +774,6 @@
    virtual Ticket AppendMessage(const Message *msg, UserData ud )
       {
+         CHECK(msg, ILLEGAL_TICKET, "NULL message");
+
          return (new MT_AppendMessage(this, ud, msg))->Start();
       }

Index: Address.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/mail/Address.cpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -b -u -2 -r1.18 -r1.19
--- Address.cpp 6 Jul 2004 13:00:50 -0000       1.18
+++ Address.cpp 23 Jun 2006 23:27:31 -0000      1.19
@@ -57,10 +57,15 @@
    AddressList_obj addrList(address);
    Address *addr = addrList->GetFirst();
-   if ( !addr || addrList->HasNext(addr) )
-   {
-      return false;
-   }
 
-   return addr->IsSameAs(*this);
+   return addr && !addrList->HasNext(addr) && IsSameAs(*addr);
+}
+
+/* static */
+bool Address::Compare(const String& address1, const String& address2)
+{
+   AddressList_obj addrList(address1);
+   Address *addr = addrList->GetFirst();
+
+   return addr && !addrList->HasNext(addr) && *addr == address2;
 }
 
@@ -250,56 +255,16 @@
 }
 
-// ----------------------------------------------------------------------------
-// AddressList
-// ----------------------------------------------------------------------------
-
-bool AddressList::HasNext(const Address *addr) const
-{
-   return GetNext(addr) != NULL;
-}
-
-bool
-operator==(const AddressList_obj& addrList1, const AddressList_obj& addrList2)
-{
-   return addrList1->IsSameAs(addrList2.operator->());
-}
-
-// ----------------------------------------------------------------------------
-// global functions
-// ----------------------------------------------------------------------------
-
+/* static */
 bool
-ContainsOwnAddress(const String& str,
-                   Profile *profile,
-                   OwnAddressKind kind,
-                   String *own)
+Address::IsInList(const wxArrayString& addresses,
+                  const String& address,
+                  String *match)
 {
-   // get the list of our own addresses
-   String returnAddrs = READ_CONFIG(profile, MP_FROM_REPLACE_ADDRESSES);
-   if ( returnAddrs == GetStringDefault(MP_FROM_REPLACE_ADDRESSES) )
-   {
-      // the default for this option is just the return address
-      returnAddrs = READ_CONFIG_TEXT(profile, MP_FROM_ADDRESS);
-   }
-
-   wxArrayString addresses = strutil_restore_array(returnAddrs);
-
-   if ( kind == OwnAddress_To )
-   {
-      // if we're interested in "own receipient" addresses, add the mailing
-      // list addresses because we normally do get mail from them
-      wxArrayString addressesML = strutil_restore_array(
-                                    READ_CONFIG(profile, MP_LIST_ADDRESSES)
-                                  );
-      WX_APPEND_ARRAY(addresses, addressesML);
-   }
-
-   const size_t count = addresses.GetCount();
+   const size_t count = addresses.size();
 
-   // now check whether any of these addresses occurs in str
    String mailbox,
           domain;
 
-   AddressList_obj addrList(str, READ_CONFIG(profile, MP_HOSTNAME));
+   AddressList_obj addrList(address);
    for ( Address *addr = addrList->GetFirst();
          addr;
@@ -328,6 +293,6 @@
                   addr->GetDomain().Matches(domain) )
          {
-            if ( own )
-               *own = addr->GetAddress();
+            if ( match )
+               *match = addr->GetAddress();
 
             return true;
@@ -339,63 +304,50 @@
 }
 
-extern String FilterAddressList(const String& original)
+// ----------------------------------------------------------------------------
+// AddressList
+// ----------------------------------------------------------------------------
+
+bool AddressList::HasNext(const Address *addr) const
 {
-   String result;
+   return GetNext(addr) != NULL;
+}
 
-   size_t each = 0;
-   while( each < original.size() )
-   {
-      bool match = false;
+bool
+operator==(const AddressList_obj& addrList1, const AddressList_obj& addrList2)
+{
+   return addrList1->IsSameAs(addrList2.operator->());
+}
 
-      if( original[each] == _T('<') )
-      {
-         size_t colon = original.find(_T(':'),each);
-         if( colon != String::npos )
-         {
-            bool alpha = true;
-            for( size_t word = each+1; alpha && word < colon; ++word )
-            {
-               if ( !( original[word] >= _T('a')
-                  && original[word] <= _T('z') ) )
-               {
-                  alpha = false;
-               }
-            }
+// ----------------------------------------------------------------------------
+// global functions
+// ----------------------------------------------------------------------------
 
-            if( alpha )
-            {
-               size_t right = original.find(_T('>'),colon);
-               if( right != String::npos )
-               {
-                  if( original.substr(each+1,colon-(each+1))
-                     == _T("mailto") )
+bool
+ContainsOwnAddress(const String& str,
+                   Profile *profile,
+                   OwnAddressKind kind,
+                   String *own)
+{
+   // get the list of our own addresses
+   String returnAddrs = READ_CONFIG(profile, MP_FROM_REPLACE_ADDRESSES);
+   if ( returnAddrs == GetStringDefault(MP_FROM_REPLACE_ADDRESSES) )
                   {
-                     size_t parameters = original.find(_T('?'),colon);
-
-                     size_t end;
-                     if( parameters != String::npos && parameters < right )
-                        end = parameters;
-                     else
-                        end = right;
-
-                     result += _T('<');
-                     result += original.substr(colon+1,end-(colon+1));
-                     result += _T('>');
+      // the default for this option is just the return address
+      returnAddrs = READ_CONFIG_TEXT(profile, MP_FROM_ADDRESS);
                   }
 
-                  match = true;
-                  each = right+1;
-               }
-            }
-         }
-      }
+   wxArrayString addresses = strutil_restore_array(returnAddrs);
 
-      if( !match )
+   if ( kind == OwnAddress_To )
       {
-         result += original[each];
-         ++each;
-      }
+      // if we're interested in "own receipient" addresses, add the mailing
+      // list addresses because we normally do get mail from them
+      wxArrayString addressesML = strutil_restore_array(
+                                    READ_CONFIG(profile, MP_LIST_ADDRESSES)
+                                  );
+      WX_APPEND_ARRAY(addresses, addressesML);
    }
 
-   return result;
+   return Address::IsInList(addresses, str, own);
 }
+

Index: HeaderInfoImpl.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/mail/HeaderInfoImpl.cpp,v
retrieving revision 1.97
retrieving revision 1.98
diff -b -u -2 -r1.97 -r1.98
--- HeaderInfoImpl.cpp  27 Sep 2004 16:22:28 -0000      1.97
+++ HeaderInfoImpl.cpp  23 Jun 2006 23:27:31 -0000      1.98
@@ -39,5 +39,5 @@
 #include "Sequence.h"
 #include "UIdArray.h"
-#include "Message.h"
+#include "Address.h"
 
 #include "gui/wxMDialogs.h"         // for MProgressInfo
@@ -413,5 +413,5 @@
       for ( size_t nAdr = 0; nAdr < nAdrCount; nAdr++ )
       {
-         if ( Message::CompareAddresses(*value, ownAddresses[nAdr]) )
+         if ( Address::Compare(*value, ownAddresses[nAdr]) )
          {
             // sender is the user himself, do the replacement

Index: MailFolder.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/mail/MailFolder.cpp,v
retrieving revision 1.320
retrieving revision 1.321
diff -b -u -2 -r1.320 -r1.321
--- MailFolder.cpp      27 May 2006 16:27:12 -0000      1.320
+++ MailFolder.cpp      23 Jun 2006 23:27:31 -0000      1.321
@@ -632,5 +632,5 @@
       // use the "To:" address of the original message for your reply as well -
       // the code below catches this particular case
-      fromMyself = Message::FindAddress(ownAddresses, rcptMain) != wxNOT_FOUND;
+      fromMyself = Address::IsInList(ownAddresses, rcptMain);
       if ( fromMyself )
       {
@@ -766,6 +766,6 @@
       // haven't used them yet
       if ( (replyKind != MailFolder::REPLY_LIST &&
-            Message::FindAddress(replyToAddresses, addr) != wxNOT_FOUND) ||
-           Message::FindAddress(ownAddresses, addr) != wxNOT_FOUND )
+               Address::IsInList(replyToAddresses, addr)) ||
+            Address::IsInList(ownAddresses, addr) )
       {
          addressesToIgnore.Add(n);
@@ -774,5 +774,5 @@
       // if we're not in REPLY_LIST mode the listAddresses array is empty
       // anyhow so it doesn't hurt
-      if ( Message::FindAddress(listAddresses, addr) != wxNOT_FOUND )
+      if ( Address::IsInList(listAddresses, addr) )
       {
          addressesList.Add(n);
@@ -842,10 +842,9 @@
             //
             // but if the dog was only cc'ed, we should keep cc'ing it
-            rcptType =
-               Message::FindAddress(replyToAddresses, address) != wxNOT_FOUND
+            rcptType = Address::IsInList(replyToAddresses, address)
                   ? Composer::Recipient_To
-                  : Message::FindAddress(ccAddresses, address) == wxNOT_FOUND
-                     ? Composer::Recipient_To
-                     : Composer::Recipient_Cc;
+                        : Address::IsInList(ccAddresses, address)
+                           ? Composer::Recipient_Cc
+                           : Composer::Recipient_To;
             break;
 

Index: Message.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/mail/Message.cpp,v
retrieving revision 1.40
retrieving revision 1.41
diff -b -u -2 -r1.40 -r1.41
--- Message.cpp 16 Jan 2006 20:32:28 -0000      1.40
+++ Message.cpp 23 Jun 2006 23:27:31 -0000      1.41
@@ -32,28 +32,5 @@
 #include "Message.h"
 
-// should be always defined now
-#define USE_ADDRESS_CLASS
-
-#ifdef USE_ADDRESS_CLASS
-   #include "Address.h"
-#endif // USE_ADDRESS_CLASS
-
-// ----------------------------------------------------------------------------
-// private functions prototypes
-// ----------------------------------------------------------------------------
-
-/// extract first and last names from an address
-static void SplitAddress(const String& addr,
-                         String *firstName,
-                         String *lastName);
-
-/// extract the full name from the address
-static void SplitAddress(const String& addr,
-                         String *fullname);
-
-/// extract the email address (without <>) from the address
-static void ExtractAddress(const String& addr,
-                           String *email);
-
+#include "Address.h"
 
 // ============================================================================
@@ -61,262 +38,4 @@
 // ============================================================================
 
-// ----------------------------------------------------------------------------
-// address helper functions
-// ----------------------------------------------------------------------------
-
-#ifdef USE_ADDRESS_CLASS
-
-static void
-SplitAddress(const String& address, String *fullname)
-{
-   CHECK_RET( fullname, _T("SplitAddress(): fullname param can't be NULL") );
-
-   AddressList_obj addrList(address);
-
-   fullname->clear();
-
-   Address *addr = addrList->GetFirst();
-   while ( addr )
-   {
-      String name = addr->GetName();
-
-      // ignore addresses without names here
-      if ( !name.empty() )
-      {
-         // separate from the previous one
-         if ( !fullname->empty() )
-         {
-            *fullname += _T(", ");
-         }
-
-         *fullname += name;
-      }
-
-      addr = addrList->GetNext(addr);
-   }
-}
-
-static void
-ExtractAddress(const String& address, String *email)
-{
-   CHECK_RET( email, _T("ExtractAddress(): email param can't be NULL") );
-
-   AddressList_obj addrList(address);
-
-   Address *addr = addrList->GetFirst();
-   if ( !addr )
-   {
-      wxLogDebug(_T("Invalid address '%s'"), address.c_str());
-
-      email->clear();
-   }
-   else // have at least one address
-   {
-      *email = addr->GetEMail();
-
-      // check that there are no more as this function doesn't work correctly
-      // (and shouldn't be used) with multiple addresses
-      ASSERT_MSG( !addrList->HasNext(addr),
-                  _T("extra addresses ignored in ExtractAddress") );
-   }
-}
-
-static void
-SplitAddress(const String& address, String *firstName, String *lastName)
-{
-   String fullname;
-   SplitAddress(address, &fullname);
-
-   const wxChar *start = fullname.c_str();
-
-   // the last name is the last word in the name part
-   String last;
-   const wxChar *p = start + fullname.length() - 1;
-   while ( p >= start && !wxIsspace(*p) )
-      last += *p--;
-
-   // first name(s) is everything preceding the last name
-   String first(start, p);
-   first.Trim();
-
-   if ( firstName )
-      *firstName = first;
-   if ( lastName )
-      *lastName = last;
-}
-
-#else // !USE_ADDRESS_CLASS
-
-// old code, unused any more
-
-static void
-SplitAddress(const String& addr,
-             String *fullname)
-{
-   CHECK_RET( fullname, _T("fullname param can't be NULL") );
-
-   // The code below will crash for empty addresses
-   if ( addr.length() == 0 )
-   {
-      *fullname = "";
-      return;
-   }
-
-   // handle not only addresses of the form
-   //         B. L. User <[EMAIL PROTECTED]>
-   // but also the alternative form specified by RFC 822
-   //         [EMAIL PROTECTED] (B. L. User)
-
-   // first check for the most common form
-   const char *addrStart = strchr(addr, '<');
-   if ( addrStart )
-   {
-      // return the part before '<'
-      *fullname = String(addr.c_str(), addrStart);
-   }
-   else // no '<' in address
-   {
-      const char *namestart = strchr(addr, '(');
-      const char *nameend = namestart ? strchr(++namestart, ')') : NULL;
-      if ( !namestart || !nameend || namestart == nameend )
-      {
-         // take the entire string as we don't which part of it is address and
-         // which is name
-         *fullname = addr;
-      }
-      else
-      {
-         // return the part between '(' and ')'
-         *fullname = String(namestart, nameend - 1);
-      }
-   }
-
-   fullname->Trim();
-
-   if ( fullname->empty() )
-   {
-      *fullname = addr;
-
-      fullname->Trim();
-   }
-}
-
-static void
-ExtractAddress(const String& addr,
-               String *email)
-{
-   *email = "";
-
-   if ( !addr )
-      return;
-
-   // first check for the most common form
-   const char *addrStart = strchr(addr, '<');
-   const char *addrEnd;
-   if ( addrStart )
-   {
-      addrStart++; // pointed at '<'
-      // return the part before the next '>'
-      addrEnd = strchr(addrStart, '>');
-      if ( !addrEnd )
-      {
-         wxLogError(_("Unmatched '<' in the email address '%s'."),
-                    addr.c_str());
-
-         return;
-      }
-   }
-   else // no '<' in address
-   {
-      // address starts at the very beginning
-      addrStart = addr.c_str();
-
-      addrEnd = strchr(addr, '(');
-      if ( !addrEnd )
-      {
-         // just take all
-         *email = addr;
-      }
-   }
-
-   // take the part of the string
-   if ( addrStart && addrEnd )
-   {
-      *email = String(addrStart, addrEnd);
-   }
-
-   // trim the address from both sides
-   email->Trim(TRUE);
-   email->Trim(FALSE);
-}
-
-static void
-SplitAddress(const String& addr,
-             String *firstName,
-             String *lastName)
-{
-   if ( addr.length() == 0 )
-   {
-      if(firstName) *firstName = wxEmptyString;
-      if(lastName) *lastName = wxEmptyString;
-      return;
-   }
-
-   String fullname;
-   SplitAddress(addr, &fullname);
-
-   const char *start = fullname.c_str();
-
-   // the last name is the last word in the name part
-   String last;
-   const char *p = start + fullname.length() - 1;
-   while ( p >= start && !isspace(*p) )
-      last += *p--;
-
-   // first name(s) is everything preceding the last name
-   String first(start, p);
-   first.Trim();
-
-   if ( firstName )
-      *firstName = first;
-   if ( lastName )
-      *lastName = last;
-}
-
-#endif // USE_ADDRESS_CLASS
-
-// ----------------------------------------------------------------------------
-// Message methods or working with addresses
-// ----------------------------------------------------------------------------
-
-/* static */ String
-Message::GetFirstNameFromAddress(const String& address)
-{
-   String first;
-   SplitAddress(address, &first, NULL);
-
-   return first;
-}
-
-/* static */ String Message::GetLastNameFromAddress(const String& address)
-{
-   String last;
-   SplitAddress(address, NULL, &last);
-
-   return last;
-}
-
-/* static */ String Message::GetNameFromAddress(const String& address)
-{
-   String name;
-   SplitAddress(address, &name);
-
-   return name;
-}
-
-// ----------------------------------------------------------------------------
-// convenience wrappers
-// ----------------------------------------------------------------------------
-
 String Message::GetAddressesString(MessageAddressType type) const
 {
@@ -331,68 +50,5 @@
 }
 
-/* static */
-String Message::GetEMailFromAddress(const String &address)
-{
-   String email;
-   ExtractAddress(address, &email);
-   return email;
-}
-
-// ----------------------------------------------------------------------------
-// Message: address comparison
-// ----------------------------------------------------------------------------
-
-/* static */
-bool Message::CompareAddresses(const String& adr1, const String& adr2)
-{
-#ifdef USE_ADDRESS_CLASS
-   AddressList_obj addrList1(adr1), addrList2(adr2);
-   return addrList1 == addrList2;
-#else // !USE_ADDRESS_CLASS
-   String email1, email2;
-
-   ExtractAddress(adr1, &email1);
-   ExtractAddress(adr2, &email2);
-
-   String mailbox, host;
-
-   // turn the hostname part to lower case:
-   mailbox = strutil_before(email1,'@');
-   host    = strutil_after(email1, '@');
-   strutil_tolower(host);
-   email1 = mailbox;
-   if(host[0u]) email1 << '@' << host;
-
-   mailbox = strutil_before(email2,'@');
-   host    = strutil_after(email2, '@');
-   strutil_tolower(host);
-   email2 = mailbox;
-   if(host[0u]) email2 << '@' << host;
-
-   // TODO the address [EMAIL PROTECTED] should be considered the same as
-   //      [EMAIL PROTECTED], for now it is not...
-
-   return email1 == email2;
-#endif // USE_ADDRESS_CLASS
-}
-
-/* static */
-int Message::FindAddress(const wxArrayString& addresses, const String& addr)
-{
-   size_t count = addresses.GetCount();
-   for ( size_t n = 0; n < count; n++ )
-   {
-      if ( CompareAddresses(addresses[n], addr) )
-         return n;
-   }
-
-   return wxNOT_FOUND;
-}
-
-// ----------------------------------------------------------------------------
-// address extraction
-// ----------------------------------------------------------------------------
-
-size_t Message::ExtractAddressesFromHeader(wxArrayString& addresses)
+size_t Message::ExtractAddressesFromHeader(wxArrayString& addresses) const
 {
    // first get all possible addresses

Index: SendMessageCC.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/mail/SendMessageCC.cpp,v
retrieving revision 1.232
retrieving revision 1.233
diff -b -u -2 -r1.232 -r1.233
--- SendMessageCC.cpp   16 Jan 2006 20:32:28 -0000      1.232
+++ SendMessageCC.cpp   23 Jun 2006 23:27:31 -0000      1.233
@@ -405,5 +405,5 @@
       m_Sender.Trim().Trim(FALSE); // remove all spaces on begin/end
 
-      if ( Message::CompareAddresses(m_From, m_Sender) )
+      if ( Address::Compare(m_From, m_Sender) )
       {
          // leave Sender empty if it is the same as From, redundant


Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Mahogany-cvsupdates mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates

Reply via email to