diff --git a/src/com/fsck/k9/K9.java b/src/com/fsck/k9/K9.java index 9322012c9..88de54e93 100644 --- a/src/com/fsck/k9/K9.java +++ b/src/com/fsck/k9/K9.java @@ -245,6 +245,13 @@ public class K9 extends Application { */ public static final int MAX_ATTACHMENT_DOWNLOAD_SIZE = (128 * 1024 * 1024); + + /* How many times should K-9 try to deliver a message before giving up + * until the app is killed and restarted + */ + + public static int MAX_SEND_ATTEMPTS = 5; + /** * Max time (in millis) the wake lock will be held for when background sync is happening */ diff --git a/src/com/fsck/k9/controller/MessagingController.java b/src/com/fsck/k9/controller/MessagingController.java index 8b96d2946..033f22f69 100644 --- a/src/com/fsck/k9/controller/MessagingController.java +++ b/src/com/fsck/k9/controller/MessagingController.java @@ -3011,6 +3011,14 @@ public class MessagingController implements Runnable { if (K9.DEBUG) Log.i(K9.LOG_TAG, "Send count for message " + message.getUid() + " is " + count.get()); + if (count.incrementAndGet() > K9.MAX_SEND_ATTEMPTS) { + Log.e(K9.LOG_TAG, "Send count for message " + message.getUid() + " can't be delivered after "+ K9.MAX_SEND_ATTEMPTS + " attempts. Giving up until the user restarts the device"); + notifySendTempFailed(account, new MessagingException(message.getSubject())); + continue; + } + + + localFolder.fetch(new Message[] { message }, fp, null); try { message.setFlag(Flag.X_SEND_IN_PROGRESS, true);