Refactoring

pull/194/merge
M66B 3 years ago
parent 3dae7c7237
commit 11c1f68534

@ -412,7 +412,7 @@ class Core {
break; break;
case EntityOperation.DELETE: case EntityOperation.DELETE:
onDelete(context, jargs, folder, message, (IMAPFolder) ifolder); onDelete(context, jargs, account, folder, message, (IMAPFolder) ifolder);
break; break;
case EntityOperation.HEADERS: case EntityOperation.HEADERS:
@ -740,20 +740,7 @@ class Core {
Long uid = null; Long uid = null;
Message[] imessages; Message[] imessages = findMsgId(context, account, ifolder, msgid);
// https://stackoverflow.com/questions/18891509/how-to-get-message-from-messageidterm-for-yahoo-imap-profile
if (account.isYahooJp()) {
Message[] itemps = ifolder.search(new ReceivedDateTerm(ComparisonTerm.GE, new Date()));
List<Message> tmp = new ArrayList<>();
for (Message itemp : itemps) {
MessageHelper helper = new MessageHelper((MimeMessage) itemp, context);
if (msgid.equals(helper.getMessageID()))
tmp.add(itemp);
}
imessages = tmp.toArray(new Message[0]);
} else
imessages = ifolder.search(new MessageIDTerm(msgid));
if (imessages != null) if (imessages != null)
for (Message iexisting : imessages) { for (Message iexisting : imessages) {
long muid = ifolder.getUID(iexisting); long muid = ifolder.getUID(iexisting);
@ -769,6 +756,21 @@ class Core {
return uid; return uid;
} }
private static Message[] findMsgId(Context context, EntityAccount account, IMAPFolder ifolder, String msgid) throws MessagingException, IOException {
// https://stackoverflow.com/questions/18891509/how-to-get-message-from-messageidterm-for-yahoo-imap-profile
if (account.isYahooJp()) {
Message[] itemps = ifolder.search(new ReceivedDateTerm(ComparisonTerm.GE, new Date()));
List<Message> tmp = new ArrayList<>();
for (Message itemp : itemps) {
MessageHelper helper = new MessageHelper((MimeMessage) itemp, context);
if (msgid.equals(helper.getMessageID()))
tmp.add(itemp);
}
return tmp.toArray(new Message[0]);
} else
return ifolder.search(new MessageIDTerm(msgid));
}
private static Message findMessage(Context context, EntityFolder folder, EntityMessage message, POP3Store istore, POP3Folder ifolder) throws MessagingException, IOException { private static Message findMessage(Context context, EntityFolder folder, EntityMessage message, POP3Store istore, POP3Folder ifolder) throws MessagingException, IOException {
Map<String, String> caps = istore.capabilities(); Map<String, String> caps = istore.capabilities();
boolean hasUidl = caps.containsKey("UIDL"); boolean hasUidl = caps.containsKey("UIDL");
@ -1124,7 +1126,7 @@ class Core {
// Some providers do not list the new message yet // Some providers do not list the new message yet
try { try {
Log.i(folder.name + " searching for added msgid=" + message.id); Log.i(folder.name + " searching for added msgid=" + message.id);
Message[] imessages = ifolder.search(new MessageIDTerm(message.msgid)); Message[] imessages = findMsgId(context, account, ifolder, message.msgid);
if (imessages != null) { if (imessages != null) {
Long found = null; Long found = null;
@ -1558,7 +1560,7 @@ class Core {
} }
} }
private static void onDelete(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, IMAPFolder ifolder) throws MessagingException { private static void onDelete(Context context, JSONArray jargs, EntityAccount account, EntityFolder folder, EntityMessage message, IMAPFolder ifolder) throws MessagingException, IOException {
// Delete message // Delete message
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
@ -1597,7 +1599,7 @@ class Core {
if (!TextUtils.isEmpty(message.msgid) && if (!TextUtils.isEmpty(message.msgid) &&
(!found || EntityFolder.DRAFTS.equals(folder.type))) (!found || EntityFolder.DRAFTS.equals(folder.type)))
try { try {
Message[] imessages = ifolder.search(new MessageIDTerm(message.msgid)); Message[] imessages = findMsgId(context, account, ifolder, message.msgid);
if (imessages == null) if (imessages == null)
Log.w(folder.name + " search for msgid=" + message.msgid + " returned null"); Log.w(folder.name + " search for msgid=" + message.msgid + " returned null");
else else
@ -1605,6 +1607,7 @@ class Core {
long muid = ifolder.getUID(iexisting); long muid = ifolder.getUID(iexisting);
if (found && muid == message.uid) if (found && muid == message.uid)
continue; continue;
Log.i(folder.name + " deleting uid=" + muid); Log.i(folder.name + " deleting uid=" + muid);
try { try {
if (perform_expunge) if (perform_expunge)

Loading…
Cancel
Save