MimeMessageBuilder uses a simple StringTokenizer for parsing the email list. It needs to be a bit more clever about it because, as Stephen Connolly pointed out, some of the chars in the delimiter-set are valid address characters in some situations - quoted local part.
public MimeMessageBuilder addRecipients(@NonNull String recipients, @NonNull Message.RecipientType recipientType) throws UnsupportedEncodingException {
AtrrayList<InternetAddress> parsed = new ArrayList<>();
try {
InternetAddress[] internetAddresses = InternetAddress.parse(recipients); // standard javax.mail works well
parsed .addAll(internetAddresses);
} catch(AddressException e) {
// thrownew exception or log when read behavior from config or system property?
// the following code run the old code default because backward compatibility, but regular expression splitter in Jenkins admin web page may be better...
StringTokenizer tokens = new StringTokenizer(recipients, " \t\n\r\f,");
while (tokens.hasMoreTokens()) {
String addressToken = tokens.nextToken();
InternetAddress internetAddress = toNormalizedAddress(addressToken);
if (internetAddress != null) {
parsed .add(internetAddress);
}
}
}
for (InternetAddress internetAddress : parsed) {
if (recipientType == Message.RecipientType.TO) {
to.add(internetAddress);
} elseif (recipientType == Message.RecipientType.CC) {
cc.add(internetAddress);
} elseif (recipientType == Message.RecipientType.BCC) {
bcc.add(internetAddress);
}
}
returnthis;
}
István Gulyás
added a comment - - edited Hello All,
I wrote here a simple code, and I suggest to use a well defined javax.mail parsing first
https://github.com/jenkinsci/mailer-plugin/blob/master/src/main/java/jenkins/plugins/mailer/tasks/MimeMessageBuilder.java#L173
public MimeMessageBuilder addRecipients(@NonNull String recipients, @NonNull Message.RecipientType recipientType) throws UnsupportedEncodingException {
AtrrayList<InternetAddress> parsed = new ArrayList<>();
try {
InternetAddress[] internetAddresses = InternetAddress.parse(recipients); // standard javax.mail works well
parsed .addAll(internetAddresses);
} catch (AddressException e) {
// throw new exception or log when read behavior from config or system property?
// the following code run the old code default because backward compatibility, but regular expression splitter in Jenkins admin web page may be better...
StringTokenizer tokens = new StringTokenizer(recipients, " \t\n\r\f," );
while (tokens.hasMoreTokens()) {
String addressToken = tokens.nextToken();
InternetAddress internetAddress = toNormalizedAddress(addressToken);
if (internetAddress != null ) {
parsed .add(internetAddress);
}
}
}
for (InternetAddress internetAddress : parsed) {
if (recipientType == Message.RecipientType.TO) {
to.add(internetAddress);
} else if (recipientType == Message.RecipientType.CC) {
cc.add(internetAddress);
} else if (recipientType == Message.RecipientType.BCC) {
bcc.add(internetAddress);
}
}
return this ;
}
Edit:
RFC822 syntax strict mode may be configurable also:
https://javaee.github.io/javamail/docs/api/javax/mail/internet/InternetAddress.html#parse-java.lang.String-boolean-
Unassigned
Tom FENNELLY
Votes:
1Vote for this issue
Watchers:
3Start watching this issue
Created:
Updated:
{"errorMessages":["jqlTooComplex"],"errors":{}}
[{"id":-1,"name":"My open issues","jql":"assignee = currentUser() AND resolution = Unresolved order by updated DESC","isSystem":true,"sharePermissions":[],"requiresLogin":true},{"id":-2,"name":"Reported by me","jql":"reporter = currentUser() order by created DESC","isSystem":true,"sharePermissions":[],"requiresLogin":true},{"id":-4,"name":"All issues","jql":"order by created DESC","isSystem":true,"sharePermissions":[],"requiresLogin":false},{"id":-5,"name":"Open issues","jql":"resolution = Unresolved order by priority DESC,updated DESC","isSystem":true,"sharePermissions":[],"requiresLogin":false},{"id":-9,"name":"Done issues","jql":"statusCategory = Done order by updated DESC","isSystem":true,"sharePermissions":[],"requiresLogin":false},{"id":-3,"name":"Viewed recently","jql":"issuekey in issueHistory() order by lastViewed DESC","isSystem":true,"sharePermissions":[],"requiresLogin":false},{"id":-6,"name":"Created recently","jql":"created >= -1w order by created DESC","isSystem":true,"sharePermissions":[],"requiresLogin":false},{"id":-7,"name":"Resolved recently","jql":"resolutiondate >= -1w order by updated DESC","isSystem":true,"sharePermissions":[],"requiresLogin":false},{"id":-8,"name":"Updated recently","jql":"updated >= -1w order by updated DESC","isSystem":true,"sharePermissions":[],"requiresLogin":false}]
Please provide some examples of failing cases.