SusiMail: Fix bug sending CC recipients as a 2nd To line

- Workaround on receive side for CC bug
- Display To and CC lists on show page
- Case-insensitive handling of all mail headers
- Early return if state is AUTH
- Escape leading '-' in q-p encoding
This commit is contained in:
zzz
2017-12-22 13:32:41 +00:00
parent 8b8d32e496
commit 7379645869
3 changed files with 65 additions and 15 deletions

View File

@@ -314,7 +314,8 @@ class Mail {
if( line.length() == 0 )
break;
if( line.startsWith( "From:" ) ) {
String hlc = line.toLowerCase(Locale.US);
if (hlc.startsWith("from:")) {
sender = line.substring( 5 ).trim();
//formattedSender = getAddress( sender );
shortSender = sender.replace("\"", "").trim();
@@ -330,7 +331,7 @@ class Mail {
if (trim)
shortSender += "…"; // must be after html encode
}
else if( line.startsWith( "Date:" ) ) {
else if (hlc.startsWith("date:")) {
dateString = line.substring( 5 ).trim();
try {
date = mailDateFormatter.parse( dateString );
@@ -344,7 +345,7 @@ class Mail {
e.printStackTrace();
}
}
else if( line.startsWith( "Subject:" ) ) {
else if (hlc.startsWith("subject:")) {
subject = line.substring( 8 ).trim();
formattedSubject = subject;
shortSubject = formattedSubject;
@@ -355,22 +356,45 @@ class Mail {
if (trim)
shortSubject += "…"; // must be after html encode
}
else if( line.toLowerCase(Locale.US).startsWith( "reply-to:" ) ) {
else if (hlc.startsWith("reply-to:")) {
reply = getAddress( line.substring( 9 ).trim() );
}
else if( line.startsWith( "To:" ) ) {
else if (hlc.startsWith("to:") ) {
ArrayList<String> list = new ArrayList<String>();
getRecipientsFromList( list, line.substring( 3 ).trim(), true );
to = list.toArray(new String[list.size()]);
if (list.isEmpty()) {
// don't set
} else if (to == null) {
to = list.toArray(new String[list.size()]);
} else if (cc == null) {
// Susimail bug before 0.9.33, sent 2nd To line that was really Cc
cc = list.toArray(new String[list.size()]);
} else {
// add to the array, shouldn't happen
for (int i = 0; i < to.length; i++) {
list.add(i, to[i]);
}
to = list.toArray(new String[list.size()]);
}
}
else if( line.startsWith( "Cc:" ) ) {
else if (hlc.startsWith("cc:")) {
ArrayList<String> list = new ArrayList<String>();
getRecipientsFromList( list, line.substring( 3 ).trim(), true );
cc = list.toArray(new String[list.size()]);
} else if(line.equals( "X-Spam-Flag: YES" )) {
if (list.isEmpty()) {
// don't set
} else if (cc == null) {
cc = list.toArray(new String[list.size()]);
} else {
// add to the array, shouldn't happen
for (int i = 0; i < cc.length; i++) {
list.add(i, cc[i]);
}
cc = list.toArray(new String[list.size()]);
}
} else if (hlc.equals("x-spam-flag: yes")) {
// TODO trust.spam.headers config
isSpam = true;
} else if(line.toLowerCase(Locale.US).startsWith("content-type:" )) {
} else if (hlc.startsWith("content-type:")) {
// this is duplicated in MailPart but
// we want to know if we have attachments, even if
// we haven't fetched the body

View File

@@ -958,6 +958,8 @@ public class WebMail extends HttpServlet
state = processLogin(sessionObject, request, state);
state = processLogout(sessionObject, request, isPOST, state);
if (state == State.AUTH)
return state;
/*
* compose dialog
@@ -2256,7 +2258,7 @@ public class WebMail extends HttpServlet
StringBuilder body = new StringBuilder(1024);
body.append( "From: " + from + "\r\n" );
Mail.appendRecipients( body, toList, "To: " );
Mail.appendRecipients( body, ccList, "To: " );
Mail.appendRecipients( body, ccList, "Cc: " );
body.append( "Subject: " );
try {
body.append( hl.encode( subject ) );
@@ -2684,8 +2686,16 @@ public class WebMail extends HttpServlet
"<tr><td align=\"right\">" + _t("From") +
":</td><td align=\"left\">" + quoteHTML( mail.sender ) + "</td></tr>\n" +
"<tr><td align=\"right\">" + _t("Subject") +
":</td><td align=\"left\"><b>" + quoteHTML( mail.formattedSubject ) + "</b></td></tr>\n" +
"<tr><td align=\"right\">" + _t("Date") +
":</td><td align=\"left\"><b>" + quoteHTML( mail.formattedSubject ) + "</b></td></tr>\n");
if (mail.to != null) {
out.println("<tr><td align=\"right\">" + _t("To") +
":</td><td align=\"left\">" + buildRecipientLine(mail.to) + "</td></tr>\n");
}
if (mail.cc != null) {
out.println("<tr><td align=\"right\">" + _t("Cc") +
":</td><td align=\"left\">" + buildRecipientLine(mail.cc) + "</td></tr>\n");
}
out.println("<tr><td align=\"right\">" + _t("Date") +
":</td><td align=\"left\">" + mail.quotedDate + "</td></tr>\n" +
"<tr><td colspan=\"2\" align=\"center\"><hr></td></tr>" +
"</table></td></tr>\n" );
@@ -2703,6 +2713,20 @@ public class WebMail extends HttpServlet
out.println( "</table></div>" );
}
/**
* TODO this is addresses only, we don't save the full line in Mail
* @since 0.9.33
*/
private static String buildRecipientLine(String[] to) {
StringBuilder buf = new StringBuilder(to.length * 16);
for (int i = 0; i < to.length; i++) {
buf.append(to[i]);
if (i < to.length - 1)
buf.append(", ");
}
return quoteHTML(buf.toString());
}
/**
* Simple configure page
*

View File

@@ -82,10 +82,12 @@ public class QuotedPrintable extends Encoding {
for( int j = 1; j < BUFSIZE; j++ )
tmp[j-1] = tmp[j];
if (c == 46 && l == 0) {
if ((c == '.' || c == '-') && l == 0) {
// leading '.' seems to get eaten by SMTP,
// even if more chars after it
String s = HexTable.table[46];
// just to be sure, do the same for '-'
// because it starts a boundary
String s = HexTable.table[c];
l = s.length();
out.append(s);
} else if (c > 32 && c < 127 && c != 61) {