Update of /cvsroot/mahogany/M/src/classes
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv7889/src/classes
Modified Files:
ComposeTemplate.cpp
Log Message:
removed deprecated address-parsing functions from Message and replaced them
with Address class methods
Index: ComposeTemplate.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/classes/ComposeTemplate.cpp,v
retrieving revision 1.74
retrieving revision 1.75
diff -b -u -2 -r1.74 -r1.75
--- ComposeTemplate.cpp 12 Feb 2006 16:50:04 -0000 1.74
+++ ComposeTemplate.cpp 23 Jun 2006 23:27:30 -0000 1.75
@@ -500,4 +500,56 @@
}
+// extract first or last name from the given string
+//
+// the logic here is primitive: the last word is taken to be the last name and
+// anything preceding it is the first name
+static String ExtractFirstOrLastName(const String& fullname, bool first)
+{
+ String value;
+
+ AddressList_obj addrList(fullname);
+ for ( Address *addr = addrList->GetFirst();
+ addr;
+ addr = addrList->GetNext(addr) )
+ {
+ if ( !value.empty() )
+ value += ", ";
+
+ const String name = addr->GetName();
+ const size_t posSpace = name.find_last_of(" ");
+ if ( posSpace == String::npos )
+ {
+ // if there are no spaces we have no choice but to take the
+ // entire name, whether we need the first or last name
+ value += name;
+ }
+ else // split the name in first and last parts
+ {
+ if ( first )
+ {
+ // first name is everything before the last word
+ value += name.substr(0, posSpace);
+ }
+ else // extract the last name
+ {
+ // last name is just the last word
+ value += name.substr(posSpace + 1);
+ }
+ }
+ }
+
+ return value;
+}
+
+static inline String ExtractFirstName(const String& fullname)
+{
+ return ExtractFirstOrLastName(fullname, true);
+}
+
+static inline String ExtractLastName(const String& fullname)
+{
+ return ExtractFirstOrLastName(fullname, false);
+}
+
// return the reply prefix to use for message quoting when replying
static String GetReplyPrefix(Message *msg, Profile *profile)
@@ -1232,13 +1284,9 @@
case MessageHeader_FirstName:
case MessageHeader_LastName:
- {
- // FIXME: this won't work if there are several addresses!
-
- wxString to = m_cv.GetRecipients(Composer::Recipient_To);
- if ( header == MessageHeader_FirstName )
- *value = Message::GetFirstNameFromAddress(to);
- else
- *value = Message::GetLastNameFromAddress(to);
- }
+ *value = ExtractFirstOrLastName
+ (
+ m_cv.GetRecipients(Composer::Recipient_To),
+ header == MessageHeader_FirstName
+ );
break;
@@ -1304,11 +1352,9 @@
case OriginalHeader_FirstName:
- *value = GetNameForAddress(m_msg, MAT_FROM);
- *value = Message::GetFirstNameFromAddress(*value);
+ *value = ExtractFirstName(GetNameForAddress(m_msg, MAT_FROM));
break;
case OriginalHeader_LastName:
- *value = GetNameForAddress(m_msg, MAT_FROM);
- *value = Message::GetLastNameFromAddress(*value);
+ *value = ExtractLastName(GetNameForAddress(m_msg, MAT_FROM));
break;
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