|
|
|
@ -45,6 +45,10 @@ import com.sun.mail.util.MessageRemovedIOException;
|
|
|
|
|
import org.jsoup.nodes.Document;
|
|
|
|
|
import org.jsoup.nodes.Element;
|
|
|
|
|
import org.jsoup.select.Elements;
|
|
|
|
|
import org.simplejavamail.outlookmessageparser.OutlookMessageParser;
|
|
|
|
|
import org.simplejavamail.outlookmessageparser.model.OutlookAttachment;
|
|
|
|
|
import org.simplejavamail.outlookmessageparser.model.OutlookFileAttachment;
|
|
|
|
|
import org.simplejavamail.outlookmessageparser.model.OutlookMessage;
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedInputStream;
|
|
|
|
|
import java.io.BufferedOutputStream;
|
|
|
|
@ -2298,6 +2302,9 @@ public class MessageHelper {
|
|
|
|
|
|
|
|
|
|
if (Helper.isTnef(local.type, local.name))
|
|
|
|
|
decodeTNEF(context, local);
|
|
|
|
|
|
|
|
|
|
if ("msg".equalsIgnoreCase(Helper.getExtension(local.name)))
|
|
|
|
|
decodeOutlook(context, local);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void downloadAttachment(Context context, int index, EntityAttachment local) throws MessagingException, IOException {
|
|
|
|
@ -2535,6 +2542,110 @@ public class MessageHelper {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void decodeOutlook(Context context, EntityAttachment local) {
|
|
|
|
|
try {
|
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
|
int subsequence = 0;
|
|
|
|
|
|
|
|
|
|
// https://poi.apache.org/components/hmef/index.html
|
|
|
|
|
File file = local.getFile(context);
|
|
|
|
|
OutlookMessage msg = new OutlookMessageParser().parseMsg(file);
|
|
|
|
|
|
|
|
|
|
String headers = msg.getHeaders();
|
|
|
|
|
if (!TextUtils.isEmpty(headers)) {
|
|
|
|
|
EntityAttachment attachment = new EntityAttachment();
|
|
|
|
|
attachment.message = local.message;
|
|
|
|
|
attachment.sequence = local.sequence;
|
|
|
|
|
attachment.subsequence = ++subsequence;
|
|
|
|
|
attachment.name = "headers.txt";
|
|
|
|
|
attachment.type = "text/rfc822-headers";
|
|
|
|
|
attachment.disposition = Part.ATTACHMENT;
|
|
|
|
|
attachment.id = db.attachment().insertAttachment(attachment);
|
|
|
|
|
|
|
|
|
|
Helper.writeText(attachment.getFile(context), headers);
|
|
|
|
|
db.attachment().setDownloaded(attachment.id, (long) headers.length());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String html = msg.getBodyHTML();
|
|
|
|
|
if (!TextUtils.isEmpty(html)) {
|
|
|
|
|
EntityAttachment attachment = new EntityAttachment();
|
|
|
|
|
attachment.message = local.message;
|
|
|
|
|
attachment.sequence = local.sequence;
|
|
|
|
|
attachment.subsequence = ++subsequence;
|
|
|
|
|
attachment.name = "body.html";
|
|
|
|
|
attachment.type = "text/html";
|
|
|
|
|
attachment.disposition = Part.ATTACHMENT;
|
|
|
|
|
attachment.id = db.attachment().insertAttachment(attachment);
|
|
|
|
|
|
|
|
|
|
File a = attachment.getFile(context);
|
|
|
|
|
Helper.writeText(a, html);
|
|
|
|
|
db.attachment().setDownloaded(attachment.id, a.length());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (TextUtils.isEmpty(html)) {
|
|
|
|
|
String text = msg.getBodyText();
|
|
|
|
|
if (!TextUtils.isEmpty(text)) {
|
|
|
|
|
EntityAttachment attachment = new EntityAttachment();
|
|
|
|
|
attachment.message = local.message;
|
|
|
|
|
attachment.sequence = local.sequence;
|
|
|
|
|
attachment.subsequence = ++subsequence;
|
|
|
|
|
attachment.name = "body.txt";
|
|
|
|
|
attachment.type = "text/plain";
|
|
|
|
|
attachment.disposition = Part.ATTACHMENT;
|
|
|
|
|
attachment.id = db.attachment().insertAttachment(attachment);
|
|
|
|
|
|
|
|
|
|
File a = attachment.getFile(context);
|
|
|
|
|
Helper.writeText(a, text);
|
|
|
|
|
db.attachment().setDownloaded(attachment.id, a.length());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String rtf = msg.getBodyRTF();
|
|
|
|
|
if (!TextUtils.isEmpty(rtf)) {
|
|
|
|
|
EntityAttachment attachment = new EntityAttachment();
|
|
|
|
|
attachment.message = local.message;
|
|
|
|
|
attachment.sequence = local.sequence;
|
|
|
|
|
attachment.subsequence = ++subsequence;
|
|
|
|
|
attachment.name = "body.rtf";
|
|
|
|
|
attachment.type = "application/rtf";
|
|
|
|
|
attachment.disposition = Part.ATTACHMENT;
|
|
|
|
|
attachment.id = db.attachment().insertAttachment(attachment);
|
|
|
|
|
|
|
|
|
|
File a = attachment.getFile(context);
|
|
|
|
|
Helper.writeText(a, rtf);
|
|
|
|
|
db.attachment().setDownloaded(attachment.id, a.length());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<OutlookAttachment> attachments = msg.getOutlookAttachments();
|
|
|
|
|
for (OutlookAttachment oa : attachments)
|
|
|
|
|
if (oa instanceof OutlookFileAttachment) {
|
|
|
|
|
OutlookFileAttachment ofa = (OutlookFileAttachment) oa;
|
|
|
|
|
|
|
|
|
|
EntityAttachment attachment = new EntityAttachment();
|
|
|
|
|
attachment.message = local.message;
|
|
|
|
|
attachment.sequence = local.sequence;
|
|
|
|
|
attachment.subsequence = ++subsequence;
|
|
|
|
|
attachment.name = ofa.getFilename();
|
|
|
|
|
attachment.type = ofa.getMimeTag();
|
|
|
|
|
attachment.disposition = Part.ATTACHMENT;
|
|
|
|
|
attachment.id = db.attachment().insertAttachment(attachment);
|
|
|
|
|
|
|
|
|
|
if (TextUtils.isEmpty(attachment.type))
|
|
|
|
|
attachment.type = Helper.guessMimeType(attachment.name);
|
|
|
|
|
|
|
|
|
|
byte[] data = ofa.getData();
|
|
|
|
|
try (OutputStream os = new FileOutputStream(attachment.getFile(context))) {
|
|
|
|
|
os.write(data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
db.attachment().setDownloaded(attachment.id, (long) data.length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
|
Log.w(ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String getWarnings(String existing) {
|
|
|
|
|
if (existing != null)
|
|
|
|
|
warnings.add(0, existing);
|
|
|
|
|