Skip to content

Commit 0576091

Browse files
committed
Fixed a bug with messages which have a state = "Sending". | #381
1 parent e30b313 commit 0576091

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

FlowCrypt/src/main/java/com/flowcrypt/email/database/dao/source/imap/MessageDaoSource.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,27 @@ JavaEmailConstants.FOLDER_OUTBOX, new MessageDaoSource().getOutboxMessages(conte
10871087
return deletedRows;
10881088
}
10891089

1090+
/**
1091+
* Add the messages which have a current state equal {@link MessageState#SENDING} to the sending queue again.
1092+
*
1093+
* @param context Interface to global information about an application environment
1094+
* @param email The email that the message linked
1095+
* @return The count of the updated row or -1 up.
1096+
*/
1097+
public int resetMsgsWithSendingState(Context context, String email) {
1098+
ContentValues contentValues = new ContentValues();
1099+
contentValues.put(COL_STATE, MessageState.QUEUED.getValue());
1100+
1101+
ContentResolver contentResolver = context.getContentResolver();
1102+
if (email != null && contentResolver != null) {
1103+
return contentResolver.update(getBaseContentUri(), contentValues,
1104+
COL_EMAIL + "= ? AND "
1105+
+ COL_FOLDER + " = ? AND "
1106+
+ COL_STATE + " = ? ",
1107+
new String[]{email, JavaEmailConstants.FOLDER_OUTBOX, String.valueOf(MessageState.SENDING.getValue())});
1108+
} else return -1;
1109+
}
1110+
10901111
private static String[] parseArray(String attributesAsString, String regex) {
10911112
if (attributesAsString != null && attributesAsString.length() > 0) {
10921113
return attributesAsString.split(regex);

FlowCrypt/src/main/java/com/flowcrypt/email/jobscheduler/MessagesSenderJobService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ protected JobParameters doInBackground(JobParameters... params) {
164164
File attachmentsCacheDirectory = new File(context.getCacheDir(), Constants.ATTACHMENTS_CACHE_DIR);
165165

166166
if (accountDao != null) {
167+
messageDaoSource.resetMsgsWithSendingState(context, accountDao.getEmail());
168+
167169
List<GeneralMessageDetails> listOfQueuedMessages = messageDaoSource.getOutboxMessages
168170
(context, accountDao.getEmail(), MessageState.QUEUED);
169171

@@ -244,6 +246,7 @@ private void sendQueuedMessages(Context context, AccountDao accountDao, MessageD
244246
uidOfLastMessage = genMsgDetails.getUid();
245247

246248
try {
249+
msgDaoSource.resetMsgsWithSendingState(context, accountDao.getEmail());
247250
msgDaoSource.updateMessageState(context, genMsgDetails.getEmail(), genMsgDetails.getLabel(),
248251
genMsgDetails.getUid(), MessageState.SENDING);
249252
Thread.sleep(2000);

0 commit comments

Comments
 (0)