Fetch on message structure exceptions

This commit is contained in:
M66B 2021-07-30 07:47:47 +02:00
parent 5785487951
commit c088c49631
2 changed files with 50 additions and 27 deletions

View File

@ -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<EntityRule> 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<EntityRule> 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);

View File

@ -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<Part> 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;
}
}
}