Author: manolo
Date: Fri May 4 07:56:34 2012
New Revision: 1333795
URL: http://svn.apache.org/viewvc?rev=1333795&view=rev
Log:
Remove quotes around names in email addresses
Modified:
james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/AbstractFetchMessagesHandler.java
james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/FetchMessagesHandlerTest.java
Modified:
james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/AbstractFetchMessagesHandler.java
URL:
http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/AbstractFetchMessagesHandler.java?rev=1333795&r1=1333794&r2=1333795&view=diff
==============================================================================
---
james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/AbstractFetchMessagesHandler.java
(original)
+++
james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/AbstractFetchMessagesHandler.java
Fri May 4 07:56:34 2012
@@ -126,25 +126,15 @@ public abstract class AbstractFetchMessa
Message m = messages[i];
String from = null;
if (m.getFrom() != null && m.getFrom().length >0 ) {
- from = m.getFrom()[0].toString().trim();
- try {
- from = MimeUtility.decodeText(from);
- userPreferences.addContact(from);
- } catch (UnsupportedEncodingException e) {
- logger.debug("Unable to decode from " + from + " " +
e.getMessage());
- }
+ from = decodeText(m.getFrom()[0].toString());
+ userPreferences.addContact(from);
}
msg.setFrom(from);
String replyto = null;
if (m.getReplyTo() != null && m.getReplyTo().length >0 ) {
- replyto = m.getReplyTo()[0].toString().trim();
- try {
- replyto = MimeUtility.decodeText(replyto);
- userPreferences.addContact(replyto);
- } catch (UnsupportedEncodingException e) {
- logger.debug("Unable to decode replyto " + replyto + " " +
e.getMessage());
- }
+ replyto = decodeText(m.getReplyTo()[0].toString());
+ userPreferences.addContact(replyto);
}
msg.setReplyto(replyto);
@@ -153,15 +143,9 @@ public abstract class AbstractFetchMessa
Address[] toArray = m.getRecipients(RecipientType.TO);
if (toArray != null) {
for (Address addr : toArray) {
- String mailTo = null;
- try {
- mailTo = MimeUtility.decodeText(addr.toString());
- userPreferences.addContact(mailTo);
- } catch (UnsupportedEncodingException e) {
- logger.debug("Unable to decode mailTo " + mailTo + " "
+ e.getMessage());
- }
- if (mailTo != null)
- to.add(mailTo);
+ String mailTo = decodeText(addr.toString());
+ userPreferences.addContact(mailTo);
+ to.add(mailTo);
}
}
msg.setTo(to);
@@ -169,11 +153,7 @@ public abstract class AbstractFetchMessa
// Check if a subject exist and if so decode it
String subject = m.getSubject();
if (subject != null) {
- try {
- subject = MimeUtility.decodeText(subject);
- } catch (UnsupportedEncodingException e) {
- logger.debug("Unable to decode subject " + subject + " " +
e.getMessage());
- }
+ subject = decodeText(subject);
}
msg.setSubject(subject);
@@ -182,15 +162,9 @@ public abstract class AbstractFetchMessa
ArrayList<String> cc = new ArrayList<String>();
if (ccArray != null) {
for (Address addr : ccArray) {
- String mailCc = null;
- try {
- mailCc = MimeUtility.decodeText(addr.toString());
- userPreferences.addContact(mailCc);
- } catch (UnsupportedEncodingException e) {
- logger.debug("Unable to decode mailTo " + mailCc + " "
+ e.getMessage());
- }
- if (mailCc != null)
- cc.add(mailCc);
+ String mailCc = decodeText(addr.toString());
+ userPreferences.addContact(mailCc);
+ cc.add(mailCc);
}
}
msg.setCc(cc);
@@ -269,4 +243,21 @@ public abstract class AbstractFetchMessa
return messages;
}
}
+
+ /**
+ * Decode iso-xxxx strings present in subjects and emails like:
+ *
+ * =?ISO-8859-1?Q?No=20hay=20ma=F1ana?= <[email protected]>
+ */
+ private String decodeText(String s) {
+ String ret = s;
+ try {
+ ret = MimeUtility.decodeText(s);
+ } catch (UnsupportedEncodingException e) {
+ logger.debug("Unable to decode text " + s + " " + e.getMessage());
+ }
+ // Remove quotes around names in email addresses
+ ret = ret.replaceFirst("^[\"' ]+(.*?)[\"' ]+<", "$1 <");
+ return ret;
+ }
}
Modified:
james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/FetchMessagesHandlerTest.java
URL:
http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/FetchMessagesHandlerTest.java?rev=1333795&r1=1333794&r2=1333795&view=diff
==============================================================================
---
james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/FetchMessagesHandlerTest.java
(original)
+++
james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/FetchMessagesHandlerTest.java
Fri May 4 07:56:34 2012
@@ -40,9 +40,9 @@ public class FetchMessagesHandlerTest ex
MockIMAPFolder f = (MockIMAPFolder)store.getFolder("WHATEVER");
f.create(Folder.HOLDS_MESSAGES);
- ByteArrayInputStream is = new ByteArrayInputStream("From:
[email protected]\nTo: [email protected]\nSubject: something\n\ndata".getBytes());
+ ByteArrayInputStream is = new ByteArrayInputStream("From:
\"[email protected]\" <[email protected]>\nTo: [email protected]\nSubject:
something\n\ndata".getBytes());
MimeMessage m1 = new MimeMessage(session, is);
- is = new ByteArrayInputStream("From: =?ISO-8859-1?Q?Manolo_Pe=F1a?=
<[email protected]>\nTo: [email protected]\nSubject: something\n\ndata".getBytes());
+ is = new ByteArrayInputStream("From:
\"=?ISO-8859-1?Q?Manolo_Pe=F1a?=\" <[email protected]>\nTo: [email protected]\nSubject:
something\n\ndata".getBytes());
MimeMessage m2 = new MimeMessage(session, is);
is = new ByteArrayInputStream("From: [email protected]\nTo:
[email protected]\nSubject: =?ISO-8859-1?Q?Monta=F1a?=\n\ndata".getBytes());
MimeMessage m3 = new MimeMessage(session, is);
@@ -52,6 +52,9 @@ public class FetchMessagesHandlerTest ex
msgs = fetchMessagesHandler.convert(10, f, new Message[]{m1, m2, m3});
assertEquals(3, msgs.size());
+
+ msgs = fetchMessagesHandler.convert(10, f, new Message[]{m1});
+ assertEquals("[email protected] <[email protected]>", msgs.get(0).getFrom());
msgs = fetchMessagesHandler.convert(10, f, new Message[]{m2});
assertEquals("Manolo Pe\u00F1a <[email protected]>",
msgs.get(0).getFrom());
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]