1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 19:52:17 -05:00

Replace the old "record a message in K9 Errors and give up"

failed-message scheme with an actual android notification that opens the
outbox
This commit is contained in:
Jesse Vincent 2010-11-13 01:47:02 +00:00
parent e964c7ba84
commit a551dc8dff
2 changed files with 15 additions and 62 deletions

View File

@ -235,8 +235,6 @@ public class K9 extends Application
*/
public static int DEFAULT_VISIBLE_LIMIT = 25;
public static int MAX_SEND_ATTEMPTS = 1;
/**
* The maximum size of an attachment we're willing to download (either View or Save)
* Attachments that are base64 encoded (most) will be about 1.375x their actual size

View File

@ -3483,7 +3483,7 @@ public class MessagingController implements Runnable
localFolder.open(OpenMode.READ_WRITE);
Message[] localMessages = localFolder.getMessages(null);
boolean anyFlagged = false;
Exception lastFailure = null;
int progress = 0;
int todo = localMessages.length;
for (MessagingListener l : getListeners())
@ -3520,13 +3520,6 @@ 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() + " has exceeded maximum attempt threshold, flagging");
message.setFlag(Flag.FLAGGED, true);
anyFlagged = true;
continue;
}
localFolder.fetch(new Message[] { message }, fp, null);
try
@ -3550,27 +3543,18 @@ public class MessagingController implements Runnable
}
else
{
LocalFolder localSentFolder =
(LocalFolder) localStore.getFolder(
account.getSentFolderName());
LocalFolder localSentFolder = (LocalFolder) localStore.getFolder( account.getSentFolderName());
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "Moving sent message to folder '" + account.getSentFolderName() + "' (" + localSentFolder.getId() + ") ");
localFolder.moveMessages(
new Message[] { message },
localSentFolder);
localFolder.moveMessages( new Message[] { message }, localSentFolder);
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "Moved sent message to folder '" + account.getSentFolderName() + "' (" + localSentFolder.getId() + ") ");
PendingCommand command = new PendingCommand();
command.command = PENDING_COMMAND_APPEND;
command.arguments =
new String[]
{
localSentFolder.getName(),
message.getUid()
};
command.arguments = new String[] { localSentFolder.getName(), message.getUid() };
queuePendingCommand(account, command);
processPendingCommands(account);
}
@ -3578,29 +3562,13 @@ public class MessagingController implements Runnable
}
catch (Exception e)
{
if (e instanceof MessagingException)
{
MessagingException me = (MessagingException)e;
if (!me.isPermanentFailure())
{
// Decrement the counter if the message could not possibly have been sent
int newVal = count.decrementAndGet();
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "Decremented send count for message " + message.getUid() + " to " + newVal
+ "; no possible send");
}
}
message.setFlag(Flag.X_SEND_FAILED, true);
Log.e(K9.LOG_TAG, "Failed to send message", e);
for (MessagingListener l : getListeners())
{
l.synchronizeMailboxFailed(
account,
localFolder.getName(),
getRootCauseMessage(e));
l.synchronizeMailboxFailed( account, localFolder.getName(), getRootCauseMessage(e));
}
addErrorMessage(account, null, e);
lastFailure = e;
}
}
catch (Exception e)
@ -3608,17 +3576,9 @@ public class MessagingController implements Runnable
Log.e(K9.LOG_TAG, "Failed to fetch message for sending", e);
for (MessagingListener l : getListeners())
{
l.synchronizeMailboxFailed(
account,
localFolder.getName(),
getRootCauseMessage(e));
l.synchronizeMailboxFailed( account, localFolder.getName(), getRootCauseMessage(e));
}
addErrorMessage(account, null, e);
/*
* We ignore this exception because a future refresh will retry this
* message.
*/
lastFailure = e;
}
}
if (localFolder.getMessageCount() == 0)
@ -3629,29 +3589,24 @@ public class MessagingController implements Runnable
{
l.sendPendingMessagesCompleted(account);
}
if (anyFlagged)
if (lastFailure != null)
{
addErrorMessage(account, mApplication.getString(R.string.send_failure_subject),
mApplication.getString(R.string.send_failure_body_fmt, K9.ERROR_FOLDER_NAME));
NotificationManager notifMgr =
(NotificationManager)mApplication.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationManager notifMgr = (NotificationManager)mApplication.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notif = new Notification(R.drawable.stat_notify_email_generic, mApplication.getString(R.string.send_failure_subject), System.currentTimeMillis());
Notification notif = new Notification(R.drawable.stat_notify_email_generic,
mApplication.getString(R.string.send_failure_subject), System.currentTimeMillis());
Intent i = MessageList.actionHandleFolderIntent(mApplication, account, account.getErrorFolderName());
Intent i = FolderList.actionHandleNotification(mApplication, account, account.getOutboxFolderName());
PendingIntent pi = PendingIntent.getActivity(mApplication, 0, i, 0);
notif.setLatestEventInfo(mApplication, mApplication.getString(R.string.send_failure_subject),
mApplication.getString(R.string.send_failure_body_abbrev, K9.ERROR_FOLDER_NAME), pi);
notif.setLatestEventInfo(mApplication, mApplication.getString(R.string.send_failure_subject), lastFailure.getMessage(), pi);
notif.flags |= Notification.FLAG_SHOW_LIGHTS;
notif.flags |= Notification.FLAG_AUTO_CANCEL;
notif.ledARGB = K9.NOTIFICATION_LED_SENDING_FAILURE_COLOR;
notif.ledOnMS = K9.NOTIFICATION_LED_FAST_ON_TIME;
notif.ledOffMS = K9.NOTIFICATION_LED_FAST_OFF_TIME;
notifMgr.notify(-1000 - account.getAccountNumber(), notif);
notifMgr.notify(-1500 - account.getAccountNumber(), notif);
}
}
catch (Exception e)