Refactoring

pull/147/head
M66B 6 years ago
parent cb36816fc5
commit 97d694e4da

@ -39,6 +39,7 @@ import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.List;
import java.util.Properties;
@ -48,6 +49,7 @@ import javax.activation.FileTypeMap;
import javax.mail.Address;
import javax.mail.BodyPart;
import javax.mail.Flags;
import javax.mail.Header;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
@ -522,6 +524,16 @@ public class MessageHelper {
return (size < 0 ? null : size);
}
String getHeaders() throws MessagingException {
StringBuilder sb = new StringBuilder();
Enumeration<Header> headers = imessage.getAllHeaders();
while (headers.hasMoreElements()) {
Header header = headers.nextElement();
sb.append(header.getName()).append(": ").append(header.getValue()).append("\n");
}
return sb.toString();
}
static String formatAddresses(Address[] addresses) {
return formatAddresses(addresses, true, false);
}

@ -76,7 +76,6 @@ import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -93,7 +92,6 @@ import javax.mail.Flags;
import javax.mail.Folder;
import javax.mail.FolderClosedException;
import javax.mail.FolderNotFoundException;
import javax.mail.Header;
import javax.mail.Message;
import javax.mail.MessageRemovedException;
import javax.mail.MessagingException;
@ -1956,22 +1954,21 @@ public class ServiceSynchronize extends LifecycleService {
}
private void doHeaders(EntityFolder folder, IMAPFolder ifolder, EntityMessage message, DB db) throws MessagingException, IOException {
Message imessage = ifolder.getMessageByUID(message.uid);
if (message.headers != null)
return;
IMAPMessage imessage = (IMAPMessage) ifolder.getMessageByUID(message.uid);
if (imessage == null)
throw new MessageRemovedException();
StringBuilder sb = new StringBuilder();
Enumeration<Header> headers = imessage.getAllHeaders();
while (headers.hasMoreElements()) {
Header header = headers.nextElement();
sb.append(header.getName()).append(": ").append(header.getValue()).append("\n");
}
db.message().setMessageHeaders(message.id, sb.toString());
MessageHelper helper = new MessageHelper(imessage);
db.message().setMessageHeaders(message.id, helper.getHeaders());
}
private void doRaw(EntityFolder folder, IMAPFolder ifolder, EntityMessage message, DB db) throws MessagingException, IOException {
if (message.raw)
return;
Message imessage = ifolder.getMessageByUID(message.uid);
if (imessage == null)
throw new MessageRemovedException();

Loading…
Cancel
Save