1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-24 02:12:15 -05:00

Merge pull request #6 from tobiasbaum/master

More small refactorings
This commit is contained in:
tobiasbaum 2014-09-28 20:10:37 +02:00
commit b8870493cd
21 changed files with 163 additions and 125 deletions

View File

@ -44,9 +44,9 @@ public class Address {
*/ */
private static final Address[] EMPTY_ADDRESS_ARRAY = new Address[0]; private static final Address[] EMPTY_ADDRESS_ARRAY = new Address[0];
String mAddress; private String mAddress;
String mPersonal; private String mPersonal;
public Address(Address address) { public Address(Address address) {

View File

@ -26,9 +26,9 @@ public abstract class Message implements Part, CompositeBody {
protected String mUid; protected String mUid;
protected Set<Flag> mFlags = new HashSet<Flag>(); private Set<Flag> mFlags = new HashSet<Flag>();
protected Date mInternalDate; private Date mInternalDate;
protected Folder mFolder; protected Folder mFolder;
@ -124,20 +124,27 @@ public abstract class Message implements Part, CompositeBody {
public abstract void setReferences(String references) throws MessagingException; public abstract void setReferences(String references) throws MessagingException;
@Override
public abstract Body getBody(); public abstract Body getBody();
@Override
public abstract String getContentType() throws MessagingException; public abstract String getContentType() throws MessagingException;
@Override
public abstract void addHeader(String name, String value) throws MessagingException; public abstract void addHeader(String name, String value) throws MessagingException;
@Override
public abstract void setHeader(String name, String value) throws MessagingException; public abstract void setHeader(String name, String value) throws MessagingException;
@Override
public abstract String[] getHeader(String name) throws MessagingException; public abstract String[] getHeader(String name) throws MessagingException;
public abstract Set<String> getHeaderNames() throws UnavailableStorageException; public abstract Set<String> getHeaderNames() throws UnavailableStorageException;
@Override
public abstract void removeHeader(String name) throws MessagingException; public abstract void removeHeader(String name) throws MessagingException;
@Override
public abstract void setBody(Body body) throws MessagingException; public abstract void setBody(Body body) throws MessagingException;
public abstract long getId(); public abstract long getId();
@ -239,6 +246,7 @@ public abstract class Message implements Part, CompositeBody {
public void destroy() throws MessagingException {} public void destroy() throws MessagingException {}
@Override
public abstract void setEncoding(String encoding) throws UnavailableStorageException, MessagingException; public abstract void setEncoding(String encoding) throws UnavailableStorageException, MessagingException;
public abstract void setCharset(String charset) throws MessagingException; public abstract void setCharset(String charset) throws MessagingException;
@ -296,6 +304,8 @@ public abstract class Message implements Part, CompositeBody {
* for more information. * for more information.
* </p> * </p>
*/ */
@Override
public abstract Message clone(); public abstract Message clone();
@Override
public abstract void setUsing7bitTransport() throws MessagingException; public abstract void setUsing7bitTransport() throws MessagingException;
} }

View File

@ -4,7 +4,7 @@ package com.fsck.k9.mail;
public class MessagingException extends Exception { public class MessagingException extends Exception {
public static final long serialVersionUID = -1; public static final long serialVersionUID = -1;
boolean permanentFailure = false; private boolean permanentFailure = false;
public MessagingException(String message) { public MessagingException(String message) {
super(message); super(message);

View File

@ -11,11 +11,11 @@ import com.fsck.k9.mail.internet.MimeUtility;
import com.fsck.k9.mail.internet.TextBody; import com.fsck.k9.mail.internet.TextBody;
public abstract class Multipart implements CompositeBody { public abstract class Multipart implements CompositeBody {
protected Part mParent; private Part mParent;
protected ArrayList<BodyPart> mParts = new ArrayList<BodyPart>(); private final ArrayList<BodyPart> mParts = new ArrayList<BodyPart>();
protected String mContentType; private String mContentType;
public void addBodyPart(BodyPart part) { public void addBodyPart(BodyPart part) {
mParts.add(part); mParts.add(part);

View File

@ -20,8 +20,8 @@ import org.apache.james.mime4j.util.MimeUtil;
* Message. * Message.
*/ */
public class MimeBodyPart extends BodyPart { public class MimeBodyPart extends BodyPart {
protected final MimeHeader mHeader = new MimeHeader(); private final MimeHeader mHeader = new MimeHeader();
protected Body mBody; private Body mBody;
public MimeBodyPart() throws MessagingException { public MimeBodyPart() throws MessagingException {
this(null); this(null);
@ -38,30 +38,36 @@ public class MimeBodyPart extends BodyPart {
setBody(body); setBody(body);
} }
protected String getFirstHeader(String name) { private String getFirstHeader(String name) {
return mHeader.getFirstHeader(name); return mHeader.getFirstHeader(name);
} }
@Override
public void addHeader(String name, String value) throws MessagingException { public void addHeader(String name, String value) throws MessagingException {
mHeader.addHeader(name, value); mHeader.addHeader(name, value);
} }
@Override
public void setHeader(String name, String value) { public void setHeader(String name, String value) {
mHeader.setHeader(name, value); mHeader.setHeader(name, value);
} }
@Override
public String[] getHeader(String name) throws MessagingException { public String[] getHeader(String name) throws MessagingException {
return mHeader.getHeader(name); return mHeader.getHeader(name);
} }
@Override
public void removeHeader(String name) throws MessagingException { public void removeHeader(String name) throws MessagingException {
mHeader.removeHeader(name); mHeader.removeHeader(name);
} }
@Override
public Body getBody() { public Body getBody() {
return mBody; return mBody;
} }
@Override
public void setBody(Body body) throws MessagingException { public void setBody(Body body) throws MessagingException {
this.mBody = body; this.mBody = body;
if (body instanceof Multipart) { if (body instanceof Multipart) {
@ -93,15 +99,18 @@ public class MimeBodyPart extends BodyPart {
setHeader(MimeHeader.HEADER_CONTENT_TRANSFER_ENCODING, encoding); setHeader(MimeHeader.HEADER_CONTENT_TRANSFER_ENCODING, encoding);
} }
@Override
public String getContentType() throws MessagingException { public String getContentType() throws MessagingException {
String contentType = getFirstHeader(MimeHeader.HEADER_CONTENT_TYPE); String contentType = getFirstHeader(MimeHeader.HEADER_CONTENT_TYPE);
return (contentType == null) ? "text/plain" : contentType; return (contentType == null) ? "text/plain" : contentType;
} }
@Override
public String getDisposition() throws MessagingException { public String getDisposition() throws MessagingException {
return getFirstHeader(MimeHeader.HEADER_CONTENT_DISPOSITION); return getFirstHeader(MimeHeader.HEADER_CONTENT_DISPOSITION);
} }
@Override
public String getContentId() throws MessagingException { public String getContentId() throws MessagingException {
String contentId = getFirstHeader(MimeHeader.HEADER_CONTENT_ID); String contentId = getFirstHeader(MimeHeader.HEADER_CONTENT_ID);
if (contentId == null) { if (contentId == null) {
@ -116,10 +125,12 @@ public class MimeBodyPart extends BodyPart {
contentId; contentId;
} }
@Override
public String getMimeType() throws MessagingException { public String getMimeType() throws MessagingException {
return MimeUtility.getHeaderParameter(getContentType(), null); return MimeUtility.getHeaderParameter(getContentType(), null);
} }
@Override
public boolean isMimeType(String mimeType) throws MessagingException { public boolean isMimeType(String mimeType) throws MessagingException {
return getMimeType().equalsIgnoreCase(mimeType); return getMimeType().equalsIgnoreCase(mimeType);
} }
@ -127,6 +138,7 @@ public class MimeBodyPart extends BodyPart {
/** /**
* Write the MimeMessage out in MIME format. * Write the MimeMessage out in MIME format.
*/ */
@Override
public void writeTo(OutputStream out) throws IOException, MessagingException { public void writeTo(OutputStream out) throws IOException, MessagingException {
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out), 1024); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out), 1024);
mHeader.writeTo(out); mHeader.writeTo(out);

View File

@ -36,7 +36,7 @@ public class MimeHeader {
HEADER_ANDROID_ATTACHMENT_STORE_DATA HEADER_ANDROID_ATTACHMENT_STORE_DATA
}; };
protected ArrayList<Field> mFields = new ArrayList<Field>(); private ArrayList<Field> mFields = new ArrayList<Field>();
private String mCharset = null; private String mCharset = null;
public void clear() { public void clear() {
@ -119,7 +119,7 @@ public class MimeHeader {
} }
// encode non printable characters except LF/CR/TAB codes. // encode non printable characters except LF/CR/TAB codes.
public boolean hasToBeEncoded(String text) { private boolean hasToBeEncoded(String text) {
for (int i = 0; i < text.length(); i++) { for (int i = 0; i < text.length(); i++) {
char c = text.charAt(i); char c = text.charAt(i);
if ((c < 0x20 || 0x7e < c) && // non printable if ((c < 0x20 || 0x7e < c) && // non printable
@ -131,10 +131,10 @@ public class MimeHeader {
return false; return false;
} }
static class Field { private static class Field {
final String name; private final String name;
final String value; private final String value;
public Field(String name, String value) { public Field(String name, String value) {
this.name = name; this.name = name;
@ -153,6 +153,7 @@ public class MimeHeader {
mCharset = charset; mCharset = charset;
} }
@Override
public MimeHeader clone() { public MimeHeader clone() {
MimeHeader header = new MimeHeader(); MimeHeader header = new MimeHeader();
header.mCharset = mCharset; header.mCharset = mCharset;

View File

@ -25,7 +25,6 @@ import org.apache.james.mime4j.stream.Field;
import org.apache.james.mime4j.stream.MimeConfig; import org.apache.james.mime4j.stream.MimeConfig;
import org.apache.james.mime4j.util.MimeUtil; import org.apache.james.mime4j.util.MimeUtil;
import com.fsck.k9.BuildConfig;
import com.fsck.k9.mail.Address; import com.fsck.k9.mail.Address;
import com.fsck.k9.mail.Body; import com.fsck.k9.mail.Body;
import com.fsck.k9.mail.BodyPart; import com.fsck.k9.mail.BodyPart;
@ -42,7 +41,7 @@ import com.fsck.k9.K9;
* RFC 2045 style headers. * RFC 2045 style headers.
*/ */
public class MimeMessage extends Message { public class MimeMessage extends Message {
protected MimeHeader mHeader = new MimeHeader(); private MimeHeader mHeader = new MimeHeader();
protected Address[] mFrom; protected Address[] mFrom;
protected Address[] mTo; protected Address[] mTo;
protected Address[] mCc; protected Address[] mCc;
@ -50,13 +49,13 @@ public class MimeMessage extends Message {
protected Address[] mReplyTo; protected Address[] mReplyTo;
protected String mMessageId; protected String mMessageId;
protected String[] mReferences; private String[] mReferences;
protected String[] mInReplyTo; private String[] mInReplyTo;
protected Date mSentDate; private Date mSentDate;
protected SimpleDateFormat mDateFormat; private SimpleDateFormat mDateFormat;
protected Body mBody; private Body mBody;
protected int mSize; protected int mSize;
public MimeMessage() { public MimeMessage() {
@ -168,20 +167,25 @@ public class MimeMessage extends Message {
return (contentType == null) ? "text/plain" : contentType; return (contentType == null) ? "text/plain" : contentType;
} }
@Override
public String getDisposition() throws MessagingException { public String getDisposition() throws MessagingException {
return getFirstHeader(MimeHeader.HEADER_CONTENT_DISPOSITION); return getFirstHeader(MimeHeader.HEADER_CONTENT_DISPOSITION);
} }
@Override
public String getContentId() throws MessagingException { public String getContentId() throws MessagingException {
return null; return null;
} }
@Override
public String getMimeType() throws MessagingException { public String getMimeType() throws MessagingException {
return MimeUtility.getHeaderParameter(getContentType(), null); return MimeUtility.getHeaderParameter(getContentType(), null);
} }
@Override
public boolean isMimeType(String mimeType) throws MessagingException { public boolean isMimeType(String mimeType) throws MessagingException {
return getMimeType().equalsIgnoreCase(mimeType); return getMimeType().equalsIgnoreCase(mimeType);
} }
@Override
public int getSize() { public int getSize() {
return mSize; return mSize;
} }
@ -410,7 +414,7 @@ public class MimeMessage extends Message {
} }
} }
protected String getFirstHeader(String name) { private String getFirstHeader(String name) {
return mHeader.getFirstHeader(name); return mHeader.getFirstHeader(name);
} }
@ -439,6 +443,7 @@ public class MimeMessage extends Message {
return mHeader.getHeaderNames(); return mHeader.getHeaderNames();
} }
@Override
public void writeTo(OutputStream out) throws IOException, MessagingException { public void writeTo(OutputStream out) throws IOException, MessagingException {
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out), 1024); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out), 1024);
@ -450,6 +455,7 @@ public class MimeMessage extends Message {
} }
} }
@Override
public InputStream getInputStream() throws MessagingException { public InputStream getInputStream() throws MessagingException {
return null; return null;
} }
@ -486,6 +492,7 @@ public class MimeMessage extends Message {
} }
} }
@Override
public void startMessage() { public void startMessage() {
if (stack.isEmpty()) { if (stack.isEmpty()) {
stack.addFirst(MimeMessage.this); stack.addFirst(MimeMessage.this);
@ -501,19 +508,23 @@ public class MimeMessage extends Message {
} }
} }
@Override
public void endMessage() { public void endMessage() {
expect(MimeMessage.class); expect(MimeMessage.class);
stack.removeFirst(); stack.removeFirst();
} }
@Override
public void startHeader() { public void startHeader() {
expect(Part.class); expect(Part.class);
} }
@Override
public void endHeader() { public void endHeader() {
expect(Part.class); expect(Part.class);
} }
@Override
public void startMultipart(BodyDescriptor bd) { public void startMultipart(BodyDescriptor bd) {
expect(Part.class); expect(Part.class);
@ -527,6 +538,7 @@ public class MimeMessage extends Message {
} }
} }
@Override
public void body(BodyDescriptor bd, InputStream in) throws IOException { public void body(BodyDescriptor bd, InputStream in) throws IOException {
expect(Part.class); expect(Part.class);
try { try {
@ -538,10 +550,12 @@ public class MimeMessage extends Message {
} }
} }
@Override
public void endMultipart() { public void endMultipart() {
stack.removeFirst(); stack.removeFirst();
} }
@Override
public void startBodyPart() { public void startBodyPart() {
expect(MimeMultipart.class); expect(MimeMultipart.class);
@ -554,11 +568,13 @@ public class MimeMessage extends Message {
} }
} }
@Override
public void endBodyPart() { public void endBodyPart() {
expect(BodyPart.class); expect(BodyPart.class);
stack.removeFirst(); stack.removeFirst();
} }
@Override
public void preamble(InputStream is) throws IOException { public void preamble(InputStream is) throws IOException {
expect(MimeMultipart.class); expect(MimeMultipart.class);
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@ -569,9 +585,11 @@ public class MimeMessage extends Message {
((MimeMultipart)stack.peek()).setPreamble(sb.toString()); ((MimeMultipart)stack.peek()).setPreamble(sb.toString());
} }
@Override
public void epilogue(InputStream is) throws IOException { public void epilogue(InputStream is) throws IOException {
} }
@Override
public void raw(InputStream is) throws IOException { public void raw(InputStream is) throws IOException {
throw new UnsupportedOperationException("Not supported"); throw new UnsupportedOperationException("Not supported");
} }
@ -621,14 +639,17 @@ public class MimeMessage extends Message {
return message; return message;
} }
@Override
public long getId() { public long getId() {
return Long.parseLong(mUid); //or maybe .mMessageId? return Long.parseLong(mUid); //or maybe .mMessageId?
} }
@Override
public String getPreview() { public String getPreview() {
return ""; return "";
} }
@Override
public boolean hasAttachments() { public boolean hasAttachments() {
return false; return false;
} }

View File

@ -10,13 +10,11 @@ import java.util.Locale;
import java.util.Random; import java.util.Random;
public class MimeMultipart extends Multipart { public class MimeMultipart extends Multipart {
protected String mPreamble; private String mPreamble;
protected String mContentType; private String mContentType;
protected String mBoundary; private final String mBoundary;
protected String mSubType;
public MimeMultipart() throws MessagingException { public MimeMultipart() throws MessagingException {
mBoundary = generateBoundary(); mBoundary = generateBoundary();
@ -26,7 +24,6 @@ public class MimeMultipart extends Multipart {
public MimeMultipart(String contentType) throws MessagingException { public MimeMultipart(String contentType) throws MessagingException {
this.mContentType = contentType; this.mContentType = contentType;
try { try {
mSubType = MimeUtility.getHeaderParameter(contentType, null).split("/")[1];
mBoundary = MimeUtility.getHeaderParameter(contentType, "boundary"); mBoundary = MimeUtility.getHeaderParameter(contentType, "boundary");
if (mBoundary == null) { if (mBoundary == null) {
throw new MessagingException("MultiPart does not contain boundary: " + contentType); throw new MessagingException("MultiPart does not contain boundary: " + contentType);
@ -62,10 +59,10 @@ public class MimeMultipart extends Multipart {
} }
public void setSubType(String subType) { public void setSubType(String subType) {
this.mSubType = subType;
mContentType = String.format("multipart/%s; boundary=\"%s\"", subType, mBoundary); mContentType = String.format("multipart/%s; boundary=\"%s\"", subType, mBoundary);
} }
@Override
public void writeTo(OutputStream out) throws IOException, MessagingException { public void writeTo(OutputStream out) throws IOException, MessagingException {
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out), 1024); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out), 1024);
@ -74,20 +71,19 @@ public class MimeMultipart extends Multipart {
writer.write("\r\n"); writer.write("\r\n");
} }
if (mParts.isEmpty()) { if (getBodyParts().isEmpty()) {
writer.write("--"); writer.write("--");
writer.write(mBoundary); writer.write(mBoundary);
writer.write("\r\n"); writer.write("\r\n");
} } else {
for (BodyPart bodyPart : getBodyParts()) {
for (int i = 0, count = mParts.size(); i < count; i++) { writer.write("--");
BodyPart bodyPart = mParts.get(i); writer.write(mBoundary);
writer.write("--"); writer.write("\r\n");
writer.write(mBoundary); writer.flush();
writer.write("\r\n"); bodyPart.writeTo(out);
writer.flush(); writer.write("\r\n");
bodyPart.writeTo(out); }
writer.write("\r\n");
} }
writer.write("--"); writer.write("--");
@ -96,13 +92,14 @@ public class MimeMultipart extends Multipart {
writer.flush(); writer.flush();
} }
@Override
public InputStream getInputStream() throws MessagingException { public InputStream getInputStream() throws MessagingException {
return null; return null;
} }
@Override @Override
public void setUsing7bitTransport() throws MessagingException { public void setUsing7bitTransport() throws MessagingException {
for (BodyPart part : mParts) { for (BodyPart part : getBodyParts()) {
part.setUsing7bitTransport(); part.setUsing7bitTransport();
} }
} }

View File

@ -927,11 +927,7 @@ public class MimeUtility {
return s.replaceAll("\r|\n", ""); return s.replaceAll("\r|\n", "");
} }
public static String decode(String s) { private static String decode(String s, Message message) {
return decode(s, null);
}
public static String decode(String s, Message message) {
if (s == null) { if (s == null) {
return null; return null;
} }
@ -1005,27 +1001,6 @@ public class MimeUtility {
return null; return null;
} }
public static Part findPartByContentId(Part part, String contentId) throws Exception {
if (part.getBody() instanceof Multipart) {
Multipart multipart = (Multipart)part.getBody();
for (BodyPart bodyPart : multipart.getBodyParts()) {
Part ret = findPartByContentId(bodyPart, contentId);
if (ret != null) {
return ret;
}
}
}
String[] header = part.getHeader(MimeHeader.HEADER_CONTENT_ID);
if (header != null) {
for (String s : header) {
if (s.equals(contentId)) {
return part;
}
}
}
return null;
}
/** /**
* Reads the Part's body and returns a String based on any charset conversion that needed * Reads the Part's body and returns a String based on any charset conversion that needed
* to be done. Note, this <b>does not</b> return a text representation of HTML. * to be done. Note, this <b>does not</b> return a text representation of HTML.
@ -1466,7 +1441,7 @@ public class MimeUtility {
* @throws MessagingException * @throws MessagingException
* In case of an error. * In case of an error.
*/ */
public static List<Viewable> getViewables(Part part, List<Part> attachments) throws MessagingException { private static List<Viewable> getViewables(Part part, List<Part> attachments) throws MessagingException {
List<Viewable> viewables = new ArrayList<Viewable>(); List<Viewable> viewables = new ArrayList<Viewable>();
Body body = part.getBody(); Body body = part.getBody();
@ -2039,7 +2014,7 @@ public class MimeUtility {
return null; return null;
} }
public static Boolean isPartTextualBody(Part part) throws MessagingException { private static Boolean isPartTextualBody(Part part) throws MessagingException {
String disposition = part.getDisposition(); String disposition = part.getDisposition();
String dispositionType = null; String dispositionType = null;
String dispositionFilename = null; String dispositionFilename = null;
@ -2127,7 +2102,7 @@ public class MimeUtility {
* *
* @see #MIME_TYPE_REPLACEMENT_MAP * @see #MIME_TYPE_REPLACEMENT_MAP
*/ */
public static String canonicalizeMimeType(String mimeType) { private static String canonicalizeMimeType(String mimeType) {
String lowerCaseMimeType = mimeType.toLowerCase(Locale.US); String lowerCaseMimeType = mimeType.toLowerCase(Locale.US);
for (String[] mimeTypeMapEntry : MIME_TYPE_REPLACEMENT_MAP) { for (String[] mimeTypeMapEntry : MIME_TYPE_REPLACEMENT_MAP) {
if (mimeTypeMapEntry[0].equals(lowerCaseMimeType)) { if (mimeTypeMapEntry[0].equals(lowerCaseMimeType)) {

View File

@ -16,7 +16,7 @@ public class TextBody implements Body {
*/ */
private static final byte[] EMPTY_BYTE_ARRAY = new byte[0]; private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
private String mBody; private final String mBody;
private String mEncoding; private String mEncoding;
private String mCharset = "UTF-8"; private String mCharset = "UTF-8";
// Length of the message composed (as opposed to quoted). I don't like the name of this variable and am open to // Length of the message composed (as opposed to quoted). I don't like the name of this variable and am open to
@ -29,6 +29,7 @@ public class TextBody implements Body {
this.mBody = body; this.mBody = body;
} }
@Override
public void writeTo(OutputStream out) throws IOException, MessagingException { public void writeTo(OutputStream out) throws IOException, MessagingException {
if (mBody != null) { if (mBody != null) {
byte[] bytes = mBody.getBytes(mCharset); byte[] bytes = mBody.getBytes(mCharset);
@ -54,6 +55,7 @@ public class TextBody implements Body {
/** /**
* Returns an InputStream that reads this body's text. * Returns an InputStream that reads this body's text.
*/ */
@Override
public InputStream getInputStream() throws MessagingException { public InputStream getInputStream() throws MessagingException {
try { try {
byte[] b; byte[] b;
@ -68,6 +70,7 @@ public class TextBody implements Body {
} }
} }
@Override
public void setEncoding(String encoding) { public void setEncoding(String encoding) {
mEncoding = encoding; mEncoding = encoding;
} }

View File

@ -204,7 +204,7 @@ public class TextBodyBuilder {
return mQuotedTextHtml; return mQuotedTextHtml;
} }
public String textToHtmlFragment(String text) { private String textToHtmlFragment(String text) {
return HtmlConverter.textToHtmlFragment(text); return HtmlConverter.textToHtmlFragment(text);
} }

View File

@ -1302,6 +1302,7 @@ public class ImapStore extends Store {
protected long getHighestUid() { protected long getHighestUid() {
try { try {
ImapSearcher searcher = new ImapSearcher() { ImapSearcher searcher = new ImapSearcher() {
@Override
public List<ImapResponse> search() throws IOException, MessagingException { public List<ImapResponse> search() throws IOException, MessagingException {
return executeSimpleCommand("UID SEARCH *:*"); return executeSimpleCommand("UID SEARCH *:*");
} }
@ -1351,6 +1352,7 @@ public class ImapStore extends Store {
ImapSearcher searcher = new ImapSearcher() { ImapSearcher searcher = new ImapSearcher() {
@Override
public List<ImapResponse> search() throws IOException, MessagingException { public List<ImapResponse> search() throws IOException, MessagingException {
return executeSimpleCommand(String.format(Locale.US, "UID SEARCH %d:%d%s%s", start, end, dateSearchString, includeDeleted ? "" : " NOT DELETED")); return executeSimpleCommand(String.format(Locale.US, "UID SEARCH %d:%d%s%s", start, end, dateSearchString, includeDeleted ? "" : " NOT DELETED"));
} }
@ -1361,6 +1363,7 @@ public class ImapStore extends Store {
protected Message[] getMessages(final List<Long> mesgSeqs, final boolean includeDeleted, final MessageRetrievalListener listener) protected Message[] getMessages(final List<Long> mesgSeqs, final boolean includeDeleted, final MessageRetrievalListener listener)
throws MessagingException { throws MessagingException {
ImapSearcher searcher = new ImapSearcher() { ImapSearcher searcher = new ImapSearcher() {
@Override
public List<ImapResponse> search() throws IOException, MessagingException { public List<ImapResponse> search() throws IOException, MessagingException {
return executeSimpleCommand(String.format("UID SEARCH %s%s", Utility.combine(mesgSeqs.toArray(), ','), includeDeleted ? "" : " NOT DELETED")); return executeSimpleCommand(String.format("UID SEARCH %s%s", Utility.combine(mesgSeqs.toArray(), ','), includeDeleted ? "" : " NOT DELETED"));
} }
@ -1371,6 +1374,7 @@ public class ImapStore extends Store {
protected Message[] getMessagesFromUids(final List<String> mesgUids, final boolean includeDeleted, final MessageRetrievalListener listener) protected Message[] getMessagesFromUids(final List<String> mesgUids, final boolean includeDeleted, final MessageRetrievalListener listener)
throws MessagingException { throws MessagingException {
ImapSearcher searcher = new ImapSearcher() { ImapSearcher searcher = new ImapSearcher() {
@Override
public List<ImapResponse> search() throws IOException, MessagingException { public List<ImapResponse> search() throws IOException, MessagingException {
return executeSimpleCommand(String.format("UID SEARCH UID %s%s", Utility.combine(mesgUids.toArray(), ','), includeDeleted ? "" : " NOT DELETED")); return executeSimpleCommand(String.format("UID SEARCH UID %s%s", Utility.combine(mesgUids.toArray(), ','), includeDeleted ? "" : " NOT DELETED"));
} }
@ -2246,6 +2250,7 @@ public class ImapStore extends Store {
// Setup the searcher // Setup the searcher
final ImapSearcher searcher = new ImapSearcher() { final ImapSearcher searcher = new ImapSearcher() {
@Override
public List<ImapResponse> search() throws IOException, MessagingException { public List<ImapResponse> search() throws IOException, MessagingException {
String imapQuery = "UID SEARCH "; String imapQuery = "UID SEARCH ";
if (requiredFlags != null) { if (requiredFlags != null) {
@ -2341,12 +2346,12 @@ public class ImapStore extends Store {
* A cacheable class that stores the details for a single IMAP connection. * A cacheable class that stores the details for a single IMAP connection.
*/ */
public static class ImapConnection { public static class ImapConnection {
protected Socket mSocket; private Socket mSocket;
protected PeekableInputStream mIn; private PeekableInputStream mIn;
protected OutputStream mOut; private OutputStream mOut;
protected ImapResponseParser mParser; private ImapResponseParser mParser;
protected int mNextCommandTag; private int mNextCommandTag;
protected Set<String> capabilities = new HashSet<String>(); private Set<String> capabilities = new HashSet<String>();
private ImapSettings mSettings; private ImapSettings mSettings;
@ -2946,7 +2951,7 @@ public class ImapStore extends Store {
static class ImapException extends MessagingException { static class ImapException extends MessagingException {
private static final long serialVersionUID = 3725007182205882394L; private static final long serialVersionUID = 3725007182205882394L;
String mAlertText; private final String mAlertText;
public ImapException(String message, String alertText) { public ImapException(String message, String alertText) {
super(message, true); super(message, true);
@ -2957,22 +2962,19 @@ public class ImapStore extends Store {
return mAlertText; return mAlertText;
} }
public void setAlertText(String alertText) {
mAlertText = alertText;
}
} }
public class ImapFolderPusher extends ImapFolder implements UntaggedHandler { public class ImapFolderPusher extends ImapFolder implements UntaggedHandler {
final PushReceiver receiver; private final PushReceiver receiver;
Thread listeningThread = null; private Thread listeningThread = null;
final AtomicBoolean stop = new AtomicBoolean(false); private final AtomicBoolean stop = new AtomicBoolean(false);
final AtomicBoolean idling = new AtomicBoolean(false); private final AtomicBoolean idling = new AtomicBoolean(false);
final AtomicBoolean doneSent = new AtomicBoolean(false); private final AtomicBoolean doneSent = new AtomicBoolean(false);
final AtomicInteger delayTime = new AtomicInteger(NORMAL_DELAY_TIME); private final AtomicInteger delayTime = new AtomicInteger(NORMAL_DELAY_TIME);
final AtomicInteger idleFailureCount = new AtomicInteger(0); private final AtomicInteger idleFailureCount = new AtomicInteger(0);
final AtomicBoolean needsPoll = new AtomicBoolean(false); private final AtomicBoolean needsPoll = new AtomicBoolean(false);
List<ImapResponse> storedUntaggedResponses = new ArrayList<ImapResponse>(); private List<ImapResponse> storedUntaggedResponses = new ArrayList<ImapResponse>();
TracingWakeLock wakeLock = null; private TracingWakeLock wakeLock = null;
public ImapFolderPusher(ImapStore store, String name, PushReceiver nReceiver) { public ImapFolderPusher(ImapStore store, String name, PushReceiver nReceiver) {
super(store, name); super(store, name);
@ -3010,6 +3012,7 @@ public class ImapStore extends Store {
public void start() { public void start() {
Runnable runner = new Runnable() { Runnable runner = new Runnable() {
@Override
public void run() { public void run() {
wakeLock.acquire(K9.PUSH_WAKE_LOCK_TIMEOUT); wakeLock.acquire(K9.PUSH_WAKE_LOCK_TIMEOUT);
if (K9.DEBUG) if (K9.DEBUG)
@ -3409,6 +3412,7 @@ public class ImapStore extends Store {
} }
} }
@Override
public void handleAsyncUntaggedResponse(ImapResponse response) { public void handleAsyncUntaggedResponse(ImapResponse response) {
if (K9.DEBUG) if (K9.DEBUG)
Log.v(K9.LOG_TAG, "Got async response: " + response); Log.v(K9.LOG_TAG, "Got async response: " + response);
@ -3459,7 +3463,7 @@ public class ImapStore extends Store {
} }
public class ImapPusher implements Pusher { public class ImapPusher implements Pusher {
final ImapStore mStore; private final ImapStore mStore;
final PushReceiver mReceiver; final PushReceiver mReceiver;
private long lastRefresh = -1; private long lastRefresh = -1;
@ -3470,6 +3474,7 @@ public class ImapStore extends Store {
mReceiver = receiver; mReceiver = receiver;
} }
@Override
public void start(List<String> folderNames) { public void start(List<String> folderNames) {
stop(); stop();
synchronized (folderPushers) { synchronized (folderPushers) {
@ -3485,6 +3490,7 @@ public class ImapStore extends Store {
} }
} }
@Override
public void refresh() { public void refresh() {
synchronized (folderPushers) { synchronized (folderPushers) {
for (ImapFolderPusher folderPusher : folderPushers.values()) { for (ImapFolderPusher folderPusher : folderPushers.values()) {
@ -3497,6 +3503,7 @@ public class ImapStore extends Store {
} }
} }
@Override
public void stop() { public void stop() {
if (K9.DEBUG) if (K9.DEBUG)
Log.i(K9.LOG_TAG, "Requested stop of IMAP pusher"); Log.i(K9.LOG_TAG, "Requested stop of IMAP pusher");
@ -3515,14 +3522,17 @@ public class ImapStore extends Store {
} }
} }
@Override
public int getRefreshInterval() { public int getRefreshInterval() {
return (getAccount().getIdleRefreshMinutes() * 60 * 1000); return (getAccount().getIdleRefreshMinutes() * 60 * 1000);
} }
@Override
public long getLastRefresh() { public long getLastRefresh() {
return lastRefresh; return lastRefresh;
} }
@Override
public void setLastRefresh(long lastRefresh) { public void setLastRefresh(long lastRefresh) {
this.lastRefresh = lastRefresh; this.lastRefresh = lastRefresh;
} }

View File

@ -1235,9 +1235,9 @@ public class Pop3Store extends Store {
} }
static class Pop3ResponseInputStream extends InputStream { static class Pop3ResponseInputStream extends InputStream {
InputStream mIn; private InputStream mIn;
boolean mStartOfLine = true; private boolean mStartOfLine = true;
boolean mFinished; private boolean mFinished;
public Pop3ResponseInputStream(InputStream in) { public Pop3ResponseInputStream(InputStream in) {
mIn = in; mIn = in;

View File

@ -176,12 +176,12 @@ public class StorageManager {
/** /**
* The root of the denoted storage. Used for mount points checking. * The root of the denoted storage. Used for mount points checking.
*/ */
protected File mRoot; private File mRoot;
/** /**
* Choosen base directory * Choosen base directory
*/ */
protected File mApplicationDir; private File mApplicationDir;
@Override @Override
public void init(final Context context) { public void init(final Context context) {
@ -258,7 +258,7 @@ public class StorageManager {
public static final String ID = "InternalStorage"; public static final String ID = "InternalStorage";
protected File mRoot; private File mRoot;
@Override @Override
public String getId() { public String getId() {
@ -328,13 +328,14 @@ public class StorageManager {
/** /**
* Root of the denoted storage. * Root of the denoted storage.
*/ */
protected File mRoot; private File mRoot;
/** /**
* Choosen base directory. * Choosen base directory.
*/ */
protected File mApplicationDirectory; private File mApplicationDirectory;
@Override
public String getId() { public String getId() {
return ID; return ID;
} }
@ -392,6 +393,7 @@ public class StorageManager {
public static final String ID = "HtcIncredibleStorage"; public static final String ID = "HtcIncredibleStorage";
@Override
public String getId() { public String getId() {
return ID; return ID;
} }
@ -428,6 +430,7 @@ public class StorageManager {
public static final String ID = "SamsungGalaxySStorage"; public static final String ID = "SamsungGalaxySStorage";
@Override
public String getId() { public String getId() {
return ID; return ID;
} }

View File

@ -12,6 +12,10 @@ import com.fsck.k9.mail.Body;
import com.fsck.k9.mail.MessagingException; import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.filter.Base64OutputStream; import com.fsck.k9.mail.filter.Base64OutputStream;
/**
* Superclass for attachments that contain binary data.
* The source for the data differs for the subclasses.
*/
public abstract class BinaryAttachmentBody implements Body { public abstract class BinaryAttachmentBody implements Body {
protected String mEncoding; protected String mEncoding;

View File

@ -9,6 +9,9 @@ import android.net.Uri;
import com.fsck.k9.mail.MessagingException; import com.fsck.k9.mail.MessagingException;
/**
* An attachment whose contents are loaded from an URI.
*/
public class LocalAttachmentBody extends BinaryAttachmentBody { public class LocalAttachmentBody extends BinaryAttachmentBody {
private Application mApplication; private Application mApplication;
private Uri mUri; private Uri mUri;

View File

@ -39,7 +39,7 @@ public class LocalMessage extends MimeMessage {
private long mThreadId; private long mThreadId;
private long mRootId; private long mRootId;
public LocalMessage(LocalStore localStore) { private LocalMessage(LocalStore localStore) {
this.localStore = localStore; this.localStore = localStore;
} }

View File

@ -38,7 +38,6 @@ import com.fsck.k9.mail.store.LockableDatabase;
import com.fsck.k9.mail.store.StorageManager; import com.fsck.k9.mail.store.StorageManager;
import com.fsck.k9.mail.store.UnavailableStorageException; import com.fsck.k9.mail.store.UnavailableStorageException;
import com.fsck.k9.mail.store.LockableDatabase.DbCallback; import com.fsck.k9.mail.store.LockableDatabase.DbCallback;
import com.fsck.k9.mail.store.LockableDatabase.SchemaDefinition;
import com.fsck.k9.mail.store.LockableDatabase.WrappedException; import com.fsck.k9.mail.store.LockableDatabase.WrappedException;
import com.fsck.k9.mail.store.StorageManager.StorageProvider; import com.fsck.k9.mail.store.StorageManager.StorageProvider;
import com.fsck.k9.provider.EmailProvider; import com.fsck.k9.provider.EmailProvider;
@ -348,15 +347,12 @@ public class LocalStore extends Store implements Serializable {
database.recreate(); database.recreate();
} }
public void pruneCachedAttachments() throws MessagingException {
pruneCachedAttachments(false);
}
/** /**
* Deletes all cached attachments for the entire store. * Deletes all cached attachments for the entire store.
* @param force * @param force
* @throws com.fsck.k9.mail.MessagingException * @throws com.fsck.k9.mail.MessagingException
*/ */
//TODO this method seems to be only called with force=true, simplify accordingly
private void pruneCachedAttachments(final boolean force) throws MessagingException { private void pruneCachedAttachments(final boolean force) throws MessagingException {
database.execute(false, new DbCallback<Void>() { database.execute(false, new DbCallback<Void>() {
@Override @Override
@ -418,10 +414,6 @@ public class LocalStore extends Store implements Serializable {
}); });
} }
public void resetVisibleLimits() throws UnavailableStorageException {
resetVisibleLimits(mAccount.getDisplayCount());
}
public void resetVisibleLimits(int visibleLimit) throws UnavailableStorageException { public void resetVisibleLimits(int visibleLimit) throws UnavailableStorageException {
final ContentValues cv = new ContentValues(); final ContentValues cv = new ContentValues();
cv.put("visible_limit", Integer.toString(visibleLimit)); cv.put("visible_limit", Integer.toString(visibleLimit));

View File

@ -8,6 +8,9 @@ import java.io.InputStream;
import com.fsck.k9.mail.MessagingException; import com.fsck.k9.mail.MessagingException;
/**
* An attachment whose contents are contained in a file.
*/
public class TempFileBody extends BinaryAttachmentBody { public class TempFileBody extends BinaryAttachmentBody {
private final File mFile; private final File mFile;

View File

@ -8,6 +8,10 @@ import org.apache.james.mime4j.util.MimeUtil;
import com.fsck.k9.mail.CompositeBody; import com.fsck.k9.mail.CompositeBody;
import com.fsck.k9.mail.MessagingException; import com.fsck.k9.mail.MessagingException;
/**
* An attachment containing a body of type message/rfc822
* whose contents are contained in a file.
*/
public class TempFileMessageBody extends TempFileBody implements CompositeBody { public class TempFileMessageBody extends TempFileBody implements CompositeBody {
public TempFileMessageBody(String filename) { public TempFileMessageBody(String filename) {

View File

@ -183,16 +183,16 @@ public class SmtpTransport extends Transport {
} }
String mHost; private String mHost;
int mPort; private int mPort;
String mUsername; private String mUsername;
String mPassword; private String mPassword;
String mClientCertificateAlias; private String mClientCertificateAlias;
AuthType mAuthType; private AuthType mAuthType;
ConnectionSecurity mConnectionSecurity; private ConnectionSecurity mConnectionSecurity;
Socket mSocket; private Socket mSocket;
PeekableInputStream mIn; private PeekableInputStream mIn;
OutputStream mOut; private OutputStream mOut;
private boolean m8bitEncodingAllowed; private boolean m8bitEncodingAllowed;
private int mLargestAcceptableMessage; private int mLargestAcceptableMessage;