SusiMail: Fix sending mail with attachments (ticket #2373)

Fix deleting attachments from drafts
Fix dup attachments after clicking add attachment without browsing first
Fix update of draft folder after saving as draft
Change text of add attachment button for clarity
Debug logging
This commit is contained in:
zzz
2019-01-15 17:18:59 +00:00
parent 16f4f04092
commit d851631494
6 changed files with 57 additions and 6 deletions

View File

@ -95,4 +95,23 @@ public class Attachment {
public void deleteData() {
data.delete();
}
/**
* @since 0.9.38
*/
@Override
public int hashCode() {
return fileName.hashCode() ^ data.hashCode();
}
/**
* @since 0.9.38
*/
@Override
public boolean equals (Object o) {
if (o == null || !(o instanceof Attachment))
return false;
Attachment a = (Attachment) o;
return fileName.equals(a.fileName) && data.equals(a.data);
}
}

View File

@ -71,7 +71,7 @@ class Draft extends Mail {
String name = DataHelper.getUTF8(b);
String type = flds[1];
String enc = flds[2];
b = Base64.decode(flds[0]);
b = Base64.decode(flds[3]);
if (b == null)
continue;
String path = DataHelper.getUTF8(b);

View File

@ -1405,15 +1405,15 @@ public class WebMail extends HttpServlet
State state = null;
String filename = request.getFilename( NEW_FILENAME );
// We handle an attachment whether sending or uploading
if (filename != null &&
(buttonPressed(request, NEW_UPLOAD) || buttonPressed(request, SEND))) {
if (filename != null && filename.length() > 0 &&
(buttonPressed(request, NEW_UPLOAD) || buttonPressed(request, SEND) || buttonPressed(request, SAVE_AS_DRAFT))) {
int i = filename.lastIndexOf('/');
if( i != - 1 )
filename = filename.substring( i + 1 );
i = filename.lastIndexOf('\\');
if( i != -1 )
filename = filename.substring( i + 1 );
if( filename != null && filename.length() > 0 ) {
if (filename.length() > 0) {
InputStream in = null;
OutputStream out = null;
I2PAppContext ctx = I2PAppContext.getGlobalContext();
@ -1452,6 +1452,12 @@ public class WebMail extends HttpServlet
sessionObject.attachments.add(
new Attachment(filename, contentType, encodeTo, f)
);
// Save the draft
String uidl = Base64.decodeToString(request.getParameter(NEW_UIDL));
if (uidl != null) {
StringBuilder draft = composeDraft(sessionObject, request);
saveDraft(sessionObject, uidl, draft);
}
} else {
sessionObject.error += _t("No Encoding found for {0}", encodeTo) + '\n';
}
@ -1466,6 +1472,7 @@ public class WebMail extends HttpServlet
state = State.NEW;
}
else if( sessionObject.attachments != null && buttonPressed( request, DELETE_ATTACHMENT ) ) {
boolean deleted = false;
for (String item : getCheckedItems(request)) {
try {
int n = Integer.parseInt(item);
@ -1473,11 +1480,21 @@ public class WebMail extends HttpServlet
Attachment attachment = sessionObject.attachments.get(i);
if( attachment.hashCode() == n ) {
sessionObject.attachments.remove( i );
attachment.deleteData();
deleted = true;
break;
}
}
} catch (NumberFormatException nfe) {}
}
// Save the draft or else the attachment comes back
if (deleted) {
String uidl = Base64.decodeToString(request.getParameter(NEW_UIDL));
if (uidl != null) {
StringBuilder draft = composeDraft(sessionObject, request);
saveDraft(sessionObject, uidl, draft);
}
}
state = State.NEW;
}
return state;
@ -2893,6 +2910,7 @@ public class WebMail extends HttpServlet
}
} else {
sessionObject.error += relay.error;
if (log.shouldWarn()) log.warn("Error sending mail: " + relay.error);
}
sessionObject.info = sessionObject.info.replace(_t("Sending mail.") + '\n', "");
}
@ -2997,7 +3015,11 @@ public class WebMail extends HttpServlet
if (!a.isEmpty()) {
if (sessionObject.attachments == null)
sessionObject.attachments = new ArrayList<Attachment>(a.size());
else
sessionObject.attachments.clear();
sessionObject.attachments.addAll(a);
} else if (sessionObject.attachments != null) {
sessionObject.attachments.clear();
}
// needed when processing the CANCEL button
out.println("<input type=\"hidden\" name=\"" + DRAFT_EXISTS + "\" value=\"1\">");
@ -3036,7 +3058,7 @@ public class WebMail extends HttpServlet
"<tr><td align=\"right\">" + _t("Subject") + ":</td><td align=\"left\"><input type=\"text\" size=\"80\" name=\"" + NEW_SUBJECT + "\" value=\"" + quoteHTML(subject) + "\"></td></tr>\n" +
"<tr><td></td><td align=\"left\"><textarea cols=\"" + Config.getProperty( CONFIG_COMPOSER_COLS, 80 )+ "\" rows=\"" + Config.getProperty( CONFIG_COMPOSER_ROWS, 10 )+ "\" name=\"" + NEW_TEXT + "\">" + text + "</textarea></td></tr>" +
"<tr class=\"bottombuttons\"><td colspan=\"2\" align=\"center\"><hr></td></tr>\n" +
"<tr class=\"bottombuttons\"><td align=\"right\">" + _t("Add Attachment") + ":</td><td id=\"addattach\" align=\"left\"><input type=\"file\" size=\"50%\" name=\"" + NEW_FILENAME + "\" value=\"\">&nbsp;" + button(NEW_UPLOAD, _t("Add another attachment")) + "</td></tr>");
"<tr class=\"bottombuttons\"><td align=\"right\">" + _t("Add Attachment") + ":</td><td id=\"addattach\" align=\"left\"><input type=\"file\" size=\"50%\" name=\"" + NEW_FILENAME + "\" value=\"\">&nbsp;" + button(NEW_UPLOAD, _t("Add Attachment")) + "</td></tr>");
if( sessionObject.attachments != null && !sessionObject.attachments.isEmpty() ) {
boolean wroteHeader = false;

View File

@ -346,6 +346,8 @@ public class SMTPClient {
error += _t("Error sending mail") + " (" + result + ")\n";
}
} catch (IOException e) {
if (_log.shouldWarn())
_log.warn("Error sending mail", e);
error += _t("Error sending mail") + ": " + e.getMessage() + '\n';
}
if( !mailSent && lastResponse.length() > 0 ) {

View File

@ -1,3 +1,11 @@
2019-01-15 zzz
* SusiMail:
- Fix sending mail with attachments (ticket #2373)
- Fix deleting attachments from drafts
- Fix dup attachments after clicking add attachment without browsing first
- Fix update of draft folder after saving as draft
- Change text of add attachment button for clarity
2019-01-13 zzz
* I2CP: Set LS2 unpublished bit, show in debug output

View File

@ -18,7 +18,7 @@ public class RouterVersion {
/** deprecated */
public final static String ID = "Monotone";
public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 16;
public final static long BUILD = 17;
/** for example "-test" */
public final static String EXTRA = "-rc";