Handle parse exception

pull/125/head
M66B 6 years ago
parent f8cc649da5
commit 2b0dc59829

@ -55,6 +55,7 @@ import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart; import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart; import javax.mail.internet.MimeMultipart;
import javax.mail.internet.ParseException;
public class MessageHelper { public class MessageHelper {
private MimeMessage imessage; private MimeMessage imessage;
@ -300,6 +301,10 @@ public class MessageHelper {
for (int len = is.read(buffer); len != -1; len = is.read(buffer)) for (int len = is.read(buffer); len != -1; len = is.read(buffer))
os.write(buffer, 0, len); os.write(buffer, 0, len);
s = new String(os.toByteArray(), "US-ASCII"); s = new String(os.toByteArray(), "US-ASCII");
} catch (IOException ex) {
// IOException; Unknown encoding: none
Log.w(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
s = ex.toString();
} }
if (part.isMimeType("text/plain")) if (part.isMimeType("text/plain"))
@ -309,6 +314,7 @@ public class MessageHelper {
if (part.isMimeType("multipart/alternative")) { if (part.isMimeType("multipart/alternative")) {
String text = null; String text = null;
try {
Multipart mp = (Multipart) part.getContent(); Multipart mp = (Multipart) part.getContent();
for (int i = 0; i < mp.getCount(); i++) { for (int i = 0; i < mp.getCount(); i++) {
Part bp = mp.getBodyPart(i); Part bp = mp.getBodyPart(i);
@ -322,16 +328,25 @@ public class MessageHelper {
} else } else
return getHtml(bp); return getHtml(bp);
} }
} catch (ParseException ex) {
// ParseException: In parameter list boundary="...">, expected parameter name, got ";"
Log.w(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
text = ex.toString();
}
return text; return text;
} }
if (part.isMimeType("multipart/*")) { if (part.isMimeType("multipart/*"))
try {
Multipart mp = (Multipart) part.getContent(); Multipart mp = (Multipart) part.getContent();
for (int i = 0; i < mp.getCount(); i++) { for (int i = 0; i < mp.getCount(); i++) {
String s = getHtml(mp.getBodyPart(i)); String s = getHtml(mp.getBodyPart(i));
if (s != null) if (s != null)
return s; return s;
} }
} catch (ParseException ex) {
Log.w(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
return ex.toString();
} }
return null; return null;
@ -340,6 +355,7 @@ public class MessageHelper {
public List<EntityAttachment> getAttachments() throws IOException, MessagingException { public List<EntityAttachment> getAttachments() throws IOException, MessagingException {
List<EntityAttachment> result = new ArrayList<>(); List<EntityAttachment> result = new ArrayList<>();
try {
Object content = imessage.getContent(); Object content = imessage.getContent();
if (content instanceof String) if (content instanceof String)
return result; return result;
@ -349,6 +365,9 @@ public class MessageHelper {
for (int i = 0; i < multipart.getCount(); i++) for (int i = 0; i < multipart.getCount(); i++)
result.addAll(getAttachments(multipart.getBodyPart(i))); result.addAll(getAttachments(multipart.getBodyPart(i)));
} }
} catch (ParseException ex) {
Log.w(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
}
return result; return result;
} }
@ -363,7 +382,11 @@ public class MessageHelper {
} catch (UnsupportedEncodingException ex) { } catch (UnsupportedEncodingException ex) {
Log.w(Helper.TAG, "attachment content type=" + part.getContentType()); Log.w(Helper.TAG, "attachment content type=" + part.getContentType());
content = part.getInputStream(); content = part.getInputStream();
} catch (ParseException ex) {
Log.w(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
content = null;
} }
if (content instanceof InputStream || content instanceof String) { if (content instanceof InputStream || content instanceof String) {
String disposition; String disposition;
try { try {

@ -521,8 +521,6 @@ public class ServiceSynchronize extends LifecycleService {
synchronizeMessage(ServiceSynchronize.this, folder, ifolder, (IMAPMessage) imessage, false); synchronizeMessage(ServiceSynchronize.this, folder, ifolder, (IMAPMessage) imessage, false);
} catch (MessageRemovedException ex) { } catch (MessageRemovedException ex) {
Log.w(Helper.TAG, folder.name + " " + ex + "\n" + Log.getStackTraceString(ex)); Log.w(Helper.TAG, folder.name + " " + ex + "\n" + Log.getStackTraceString(ex));
} catch (Throwable ex) {
Log.e(Helper.TAG, folder.name + " " + ex + "\n" + Log.getStackTraceString(ex));
} }
EntityOperation.process(ServiceSynchronize.this); // download small attachments EntityOperation.process(ServiceSynchronize.this); // download small attachments
} catch (Throwable ex) { } catch (Throwable ex) {
@ -585,8 +583,6 @@ public class ServiceSynchronize extends LifecycleService {
EntityOperation.process(ServiceSynchronize.this); // download small attachments EntityOperation.process(ServiceSynchronize.this); // download small attachments
} catch (MessageRemovedException ex) { } catch (MessageRemovedException ex) {
Log.w(Helper.TAG, folder.name + " " + ex + "\n" + Log.getStackTraceString(ex)); Log.w(Helper.TAG, folder.name + " " + ex + "\n" + Log.getStackTraceString(ex));
} catch (Throwable ex) {
Log.e(Helper.TAG, folder.name + " " + ex + "\n" + Log.getStackTraceString(ex));
} }
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(Helper.TAG, folder.name + " " + ex + "\n" + Log.getStackTraceString(ex)); Log.e(Helper.TAG, folder.name + " " + ex + "\n" + Log.getStackTraceString(ex));
@ -1286,10 +1282,6 @@ public class ServiceSynchronize extends LifecycleService {
unchanged++; unchanged++;
} catch (MessageRemovedException ex) { } catch (MessageRemovedException ex) {
Log.w(Helper.TAG, folder.name + " " + ex + "\n" + Log.getStackTraceString(ex)); Log.w(Helper.TAG, folder.name + " " + ex + "\n" + Log.getStackTraceString(ex));
} catch (FolderClosedException ex) {
throw ex;
} catch (Throwable ex) {
Log.e(Helper.TAG, folder.name + " " + ex + "\n" + Log.getStackTraceString(ex));
} }
EntityOperation.process(this); // download small attachments EntityOperation.process(this); // download small attachments

Loading…
Cancel
Save