Close SMTP connection before post processing

pull/184/head
M66B 5 years ago
parent c029840180
commit b81af0a63a

@ -577,6 +577,8 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
}
// Create transport
long start, end;
Long max_size = null;
try (EmailService iservice = new EmailService(
this, ident.getProtocol(), ident.realm, ident.encryption, ident.insecure, debug)) {
iservice.setUseIp(ident.use_ip, ident.ehlo);
@ -589,11 +591,8 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
throw new IOException("Test");
db.identity().setIdentityState(ident.id, "connected");
if (ident.max_size == null) {
Long max_size = iservice.getMaxSize();
if (max_size != null)
db.identity().setIdentityMaxSize(ident.id, max_size);
}
if (ident.max_size == null)
max_size = iservice.getMaxSize();
Address[] to = imessage.getAllRecipients();
String via = "via " + ident.host + "/" + ident.user +
@ -601,10 +600,22 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
// Send message
EntityLog.log(this, "Sending " + via);
long start = new Date().getTime();
start = new Date().getTime();
iservice.getTransport().sendMessage(imessage, to);
long end = new Date().getTime();
end = new Date().getTime();
EntityLog.log(this, "Sent " + via + " elapse=" + (end - start) + " ms");
} catch (MessagingException ex) {
Log.e(ex);
if (sid != null)
db.message().deleteMessage(sid);
db.identity().setIdentityError(ident.id, Log.formatThrowable(ex));
throw ex;
} finally {
db.identity().setIdentityState(ident.id, null);
}
try {
db.beginTransaction();
@ -619,19 +630,23 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
db.message().setMessageUiHide(sid, false);
}
// Mark replied
if (message.inreplyto != null) {
List<EntityMessage> replieds = db.message().getMessagesByMsgId(message.account, message.inreplyto);
for (EntityMessage replied : replieds)
EntityOperation.queue(this, replied, EntityOperation.ANSWERED, true);
}
// Mark forwarded
if (message.wasforwardedfrom != null) {
List<EntityMessage> forwardeds = db.message().getMessagesByMsgId(message.account, message.wasforwardedfrom);
for (EntityMessage forwarded : forwardeds)
EntityOperation.queue(this, forwarded, EntityOperation.KEYWORD, "$Forwarded", true);
}
// Reset identity
// Update identity
if (max_size != null)
db.identity().setIdentityMaxSize(ident.id, max_size);
db.identity().setIdentityConnected(ident.id, new Date().getTime());
db.identity().setIdentityError(ident.id, null);
@ -668,18 +683,6 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
ServiceSynchronize.eval(this, "orphan");
}
} catch (MessagingException ex) {
Log.e(ex);
if (sid != null)
db.message().deleteMessage(sid);
db.identity().setIdentityError(ident.id, Log.formatThrowable(ex));
throw ex;
} finally {
db.identity().setIdentityState(ident.id, null);
}
}
static void boot(final Context context) {

Loading…
Cancel
Save