|
|
|
@ -294,7 +294,7 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
|
|
|
|
|
.setSmallIcon(R.drawable.baseline_warning_white_24)
|
|
|
|
|
.setContentTitle(getString(R.string.title_notification_sending_failed, recipient))
|
|
|
|
|
.setContentIntent(getPendingIntent(this))
|
|
|
|
|
.setAutoCancel(tries_left != 0)
|
|
|
|
|
.setAutoCancel(true)
|
|
|
|
|
.setShowWhen(true)
|
|
|
|
|
.setPriority(NotificationCompat.PRIORITY_MAX)
|
|
|
|
|
.setOnlyAlertOnce(false)
|
|
|
|
@ -573,7 +573,7 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
|
|
|
|
|
// Requeue non executing operations
|
|
|
|
|
for (long id : db.message().getMessageByFolder(outbox.id)) {
|
|
|
|
|
EntityMessage message = db.message().getMessage(id);
|
|
|
|
|
if (message == null)
|
|
|
|
|
if (message == null || message.warning != null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
EntityOperation op = db.operation().getOperation(message.id, EntityOperation.SEND);
|
|
|
|
@ -623,6 +623,7 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
|
|
|
|
|
nm.notify(NotificationHelper.NOTIFICATION_SEND, getNotificationService(true));
|
|
|
|
|
|
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
|
boolean send_partial = prefs.getBoolean("send_partial", false);
|
|
|
|
|
boolean reply_move = prefs.getBoolean("reply_move", false);
|
|
|
|
|
boolean reply_move_inbox = prefs.getBoolean("reply_move_inbox", true);
|
|
|
|
|
boolean protocol = prefs.getBoolean("protocol", false);
|
|
|
|
@ -761,8 +762,10 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create transport
|
|
|
|
|
long start, end;
|
|
|
|
|
long start = 0;
|
|
|
|
|
long end = 0;
|
|
|
|
|
Long max_size = null;
|
|
|
|
|
SMTPSendFailedException partial = null;
|
|
|
|
|
if (ident.auth_type == AUTH_TYPE_GRAPH) {
|
|
|
|
|
start = new Date().getTime();
|
|
|
|
|
MicrosoftGraph.send(ServiceSend.this, ident, imessage);
|
|
|
|
@ -770,6 +773,8 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
|
|
|
|
|
} else {
|
|
|
|
|
EmailService iservice = new EmailService(this, ident, EmailService.PURPOSE_USE, debug);
|
|
|
|
|
try {
|
|
|
|
|
if (send_partial)
|
|
|
|
|
iservice.setSendPartial(true);
|
|
|
|
|
iservice.setUseIp(ident.use_ip, ident.ehlo);
|
|
|
|
|
if (!message.isSigned() && !message.isEncrypted())
|
|
|
|
|
iservice.set8BitMime(ident.octetmime);
|
|
|
|
@ -820,6 +825,12 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
|
|
|
|
|
recipients.add(a);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (BuildConfig.DEBUG && false) {
|
|
|
|
|
InternetAddress invalid = new InternetAddress();
|
|
|
|
|
invalid.setAddress("invalid");
|
|
|
|
|
recipients.add(invalid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (protocol && BuildConfig.DEBUG) {
|
|
|
|
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
|
|
|
|
imessage.writeTo(bos);
|
|
|
|
@ -855,15 +866,27 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
|
|
|
|
|
// Send message
|
|
|
|
|
EntityLog.log(this, "Sending " + via);
|
|
|
|
|
start = new Date().getTime();
|
|
|
|
|
try {
|
|
|
|
|
iservice.getTransport().sendMessage(imessage, rcptto);
|
|
|
|
|
} finally {
|
|
|
|
|
end = new Date().getTime();
|
|
|
|
|
}
|
|
|
|
|
EntityLog.log(this, "Sent " + via + " elapse=" + (end - start) + " ms");
|
|
|
|
|
} catch (MessagingException ex) {
|
|
|
|
|
|
|
|
|
|
iservice.dump(ident.email);
|
|
|
|
|
Log.e(ex);
|
|
|
|
|
|
|
|
|
|
if (ex instanceof SMTPSendFailedException) {
|
|
|
|
|
SMTPSendFailedException sem = (SMTPSendFailedException) ex;
|
|
|
|
|
if (send_partial &&
|
|
|
|
|
sem.getInvalidAddresses() != null &&
|
|
|
|
|
sem.getValidSentAddresses() != null &&
|
|
|
|
|
sem.getValidUnsentAddresses() != null &&
|
|
|
|
|
sem.getValidSentAddresses().length > 0 &&
|
|
|
|
|
sem.getInvalidAddresses().length + sem.getValidUnsentAddresses().length > 0) {
|
|
|
|
|
partial = sem;
|
|
|
|
|
}
|
|
|
|
|
ex = new SMTPSendFailedException(
|
|
|
|
|
sem.getCommand(),
|
|
|
|
|
sem.getReturnCode(),
|
|
|
|
@ -874,11 +897,12 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
|
|
|
|
|
sem.getInvalidAddresses());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sid != null)
|
|
|
|
|
if (sid != null && partial == null)
|
|
|
|
|
db.message().deleteMessage(sid);
|
|
|
|
|
|
|
|
|
|
db.identity().setIdentityError(ident.id, Log.formatThrowable(ex));
|
|
|
|
|
|
|
|
|
|
if (partial == null)
|
|
|
|
|
throw ex;
|
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
|
iservice.dump(ident.email);
|
|
|
|
@ -898,7 +922,20 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
|
|
|
|
|
db.beginTransaction();
|
|
|
|
|
|
|
|
|
|
// Delete from outbox
|
|
|
|
|
if (partial == null)
|
|
|
|
|
db.message().deleteMessage(message.id);
|
|
|
|
|
else {
|
|
|
|
|
Throwable ex = new Throwable(getString(R.string.title_advanced_sent_partially), partial);
|
|
|
|
|
db.message().setMessageWarning(message.id, Log.formatThrowable(ex));
|
|
|
|
|
if (NotificationHelper.areNotificationsEnabled(nm)) {
|
|
|
|
|
NotificationCompat.Builder builder = getNotificationError(
|
|
|
|
|
MessageHelper.formatAddressesShort(message.to),
|
|
|
|
|
ex, 0);
|
|
|
|
|
nm.notify("partial:" + message.id,
|
|
|
|
|
NotificationHelper.NOTIFICATION_TAGGED,
|
|
|
|
|
builder.build());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Show in sent folder
|
|
|
|
|
if (sid != null) {
|
|
|
|
@ -907,6 +944,20 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
|
|
|
|
|
db.attachment().deleteAttachments(sid,
|
|
|
|
|
new int[]{EntityAttachment.PGP_MESSAGE, EntityAttachment.SMIME_MESSAGE});
|
|
|
|
|
|
|
|
|
|
if (partial != null) {
|
|
|
|
|
List<Address> unsent = new ArrayList<>();
|
|
|
|
|
if (partial.getInvalidAddresses() != null)
|
|
|
|
|
unsent.addAll(Arrays.asList(partial.getInvalidAddresses()));
|
|
|
|
|
if (partial.getValidUnsentAddresses() != null)
|
|
|
|
|
unsent.addAll(Arrays.asList(partial.getValidUnsentAddresses()));
|
|
|
|
|
db.message().setMessageTo(sid,
|
|
|
|
|
DB.Converters.encodeAddresses(MessageHelper.removeAddresses(message.to, unsent)));
|
|
|
|
|
db.message().setMessageCc(sid,
|
|
|
|
|
DB.Converters.encodeAddresses(MessageHelper.removeAddresses(message.cc, unsent)));
|
|
|
|
|
db.message().setMessageBcc(sid,
|
|
|
|
|
DB.Converters.encodeAddresses(MessageHelper.removeAddresses(message.bcc, unsent)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
db.message().setMessageReceived(sid, start);
|
|
|
|
|
db.message().setMessageSent(sid, end);
|
|
|
|
|
db.message().setMessageUiHide(sid, false);
|
|
|
|
|