1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-30 13:12:25 -05:00

Add a method to calculate a message's serialized size

This commit is contained in:
Jesse Vincent 2011-03-27 23:06:08 +08:00
parent c8d38da568
commit 604e532879

View File

@ -4,8 +4,17 @@ package com.fsck.k9.mail;
import java.util.Date; import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.io.IOException;
import android.util.Log;
import com.fsck.k9.activity.MessageReference; import com.fsck.k9.activity.MessageReference;
import com.fsck.k9.mail.filter.CountingOutputStream;
import com.fsck.k9.mail.filter.EOLConvertingOutputStream;
import com.fsck.k9.mail.store.UnavailableStorageException; import com.fsck.k9.mail.store.UnavailableStorageException;
import com.fsck.k9.K9;
public abstract class Message implements Part, Body { public abstract class Message implements Part, Body {
private static final Flag[] EMPTY_FLAG_ARRAY = new Flag[0]; private static final Flag[] EMPTY_FLAG_ARRAY = new Flag[0];
@ -199,4 +208,20 @@ public abstract class Message implements Part, Body {
return tmpReference.equals(ref); return tmpReference.equals(ref);
} }
public long calculateSize() {
try {
CountingOutputStream out = new CountingOutputStream();
EOLConvertingOutputStream eolOut = new EOLConvertingOutputStream(out);
writeTo(eolOut);
eolOut.flush();
return out.getCount();
} catch (IOException e) {
Log.e(K9.LOG_TAG, "Failed to calculate a message size: " + e);
} catch (MessagingException e) {
Log.e(K9.LOG_TAG, "Failed to calculate a message size: " + e);
}
return 0;
}
} }