From c088c49631c142b485329ff1dd2028c873e1e35b Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 30 Jul 2021 07:47:47 +0200 Subject: [PATCH] Fetch on message structure exceptions --- app/src/main/java/eu/faircode/email/Core.java | 28 +++++++++-- .../java/eu/faircode/email/MessageHelper.java | 49 ++++++++++--------- 2 files changed, 50 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index 851803e833..5e49ce2f93 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -19,6 +19,11 @@ package eu.faircode.email; Copyright 2018-2021 by Marcel Bokhorst (M66B) */ +import static android.os.Process.THREAD_PRIORITY_BACKGROUND; +import static androidx.core.app.NotificationCompat.DEFAULT_LIGHTS; +import static androidx.core.app.NotificationCompat.DEFAULT_SOUND; +import static javax.mail.Folder.READ_WRITE; + import android.app.AlarmManager; import android.app.Notification; import android.app.NotificationChannel; @@ -130,11 +135,6 @@ import javax.mail.search.SentDateTerm; import me.leolin.shortcutbadger.ShortcutBadger; -import static android.os.Process.THREAD_PRIORITY_BACKGROUND; -import static androidx.core.app.NotificationCompat.DEFAULT_LIGHTS; -import static androidx.core.app.NotificationCompat.DEFAULT_SOUND; -import static javax.mail.Folder.READ_WRITE; - class Core { private static final int MAX_NOTIFICATION_DISPLAY = 10; // per group private static final int MAX_NOTIFICATION_COUNT = 100; // per group @@ -3177,6 +3177,24 @@ class Core { IMAPStore istore, IMAPFolder ifolder, MimeMessage imessage, boolean browsed, boolean download, List rules, State state, SyncStats stats) throws MessagingException, IOException { + try { + return _synchronizeMessage(context, account, folder, + istore, ifolder, imessage, + browsed, download, rules, state, stats); + } catch (MessageHelper.MessagingStructureException ex) { + Log.e(ex); + long uid = ifolder.getUID(imessage); + EntityOperation.queue(context, folder, EntityOperation.FETCH, uid); + return null; + } + } + + private static EntityMessage _synchronizeMessage( + Context context, + EntityAccount account, EntityFolder folder, + IMAPStore istore, IMAPFolder ifolder, MimeMessage imessage, + boolean browsed, boolean download, + List rules, State state, SyncStats stats) throws MessagingException, IOException { DB db = DB.getInstance(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean download_headers = prefs.getBoolean("download_headers", false); diff --git a/app/src/main/java/eu/faircode/email/MessageHelper.java b/app/src/main/java/eu/faircode/email/MessageHelper.java index 39adb080c3..ade3dfc0bf 100644 --- a/app/src/main/java/eu/faircode/email/MessageHelper.java +++ b/app/src/main/java/eu/faircode/email/MessageHelper.java @@ -19,12 +19,15 @@ package eu.faircode.email; Copyright 2018-2021 by Marcel Bokhorst (M66B) */ +import static android.system.OsConstants.ENOSPC; + import android.content.Context; import android.content.SharedPreferences; import android.net.Uri; import android.system.ErrnoException; import android.text.TextUtils; +import androidx.annotation.Nullable; import androidx.core.net.MailTo; import androidx.documentfile.provider.DocumentFile; import androidx.preference.PreferenceManager; @@ -109,8 +112,6 @@ import javax.mail.internet.ParseException; import biweekly.Biweekly; import biweekly.ICalendar; -import static android.system.OsConstants.ENOSPC; - public class MessageHelper { private boolean ensuredEnvelope = false; private boolean ensuredHeaders = false; @@ -2509,11 +2510,8 @@ public class MessageHelper { break; } } - } else { - String msg = "Multipart=" + (content == null ? null : content.getClass().getName()); - Log.e(msg); - throw new MessagingException(msg); - } + } else + throw new MessagingStructureException(content); } if (part.isMimeType("multipart/signed")) { @@ -2557,11 +2555,8 @@ public class MessageHelper { sb.append(' ').append(i).append('=').append(multipart.getBodyPart(i).getContentType()); Log.e(sb.toString()); } - } else { - String msg = "Multipart=" + (content == null ? null : content.getClass().getName()); - Log.e(msg); - throw new MessagingException(msg); - } + } else + throw new MessagingStructureException(content); } else Log.e(ct.toString()); } else if (part.isMimeType("multipart/encrypted")) { @@ -2582,11 +2577,8 @@ public class MessageHelper { sb.append(' ').append(i).append('=').append(multipart.getBodyPart(i).getContentType()); Log.e(sb.toString()); } - } else { - String msg = "Multipart=" + (content == null ? null : content.getClass().getName()); - Log.e(msg); - throw new MessagingException(msg); - } + } else + throw new MessagingStructureException(content); } else Log.e(ct.toString()); } else if (part.isMimeType("application/pkcs7-mime") || @@ -2661,11 +2653,8 @@ public class MessageHelper { Object content = part.getContent(); // Should always be Multipart if (content instanceof Multipart) multipart = (Multipart) part.getContent(); - else { - String msg = "Multipart=" + (content == null ? null : content.getClass().getName()); - Log.e(msg); - throw new MessagingException(msg); - } + else + throw new MessagingStructureException(content); boolean other = false; List plain = new ArrayList<>(); @@ -3049,4 +3038,20 @@ public class MessageHelper { return values; } + + static class MessagingStructureException extends MessagingException { + private String className; + + MessagingStructureException(Object content) { + super(); + if (content != null) + this.className = content.getClass().getName(); + } + + @Nullable + @Override + public String getMessage() { + return className; + } + } }