Refactoring, cleanup

This commit is contained in:
M66B 2018-12-25 08:22:07 +00:00
parent a5e4b86776
commit 27686c9a8b
3 changed files with 29 additions and 46 deletions

View File

@ -255,11 +255,11 @@ public class EntityMessage implements Serializable {
//(this.inreplyto == null ? other.inreplyto == null : this.inreplyto.equals(other.inreplyto)) &&
(this.thread == null ? other.thread == null : this.thread.equals(other.thread)) &&
(this.avatar == null ? other.avatar == null : this.avatar.equals(other.avatar)) &&
equal(this.from, other.from) &&
equal(this.to, other.to) &&
equal(this.cc, other.cc) &&
equal(this.bcc, other.bcc) &&
equal(this.reply, other.reply) &&
MessageHelper.equal(this.from, other.from) &&
MessageHelper.equal(this.to, other.to) &&
MessageHelper.equal(this.cc, other.cc) &&
MessageHelper.equal(this.bcc, other.bcc) &&
MessageHelper.equal(this.reply, other.reply) &&
(this.headers == null ? other.headers == null : this.headers.equals(other.headers)) &&
(this.subject == null ? other.subject == null : this.subject.equals(other.subject)) &&
(this.size == null ? other.size == null : this.size.equals(other.size)) &&
@ -300,11 +300,11 @@ public class EntityMessage implements Serializable {
(this.inreplyto == null ? other.inreplyto == null : this.inreplyto.equals(other.inreplyto)) &&
(this.thread == null ? other.thread == null : this.thread.equals(other.thread)) &&
(this.avatar == null ? other.avatar == null : this.avatar.equals(other.avatar)) &&
equal(this.from, other.from) &&
equal(this.to, other.to) &&
equal(this.cc, other.cc) &&
equal(this.bcc, other.bcc) &&
equal(this.reply, other.reply) &&
MessageHelper.equal(this.from, other.from) &&
MessageHelper.equal(this.to, other.to) &&
MessageHelper.equal(this.cc, other.cc) &&
MessageHelper.equal(this.bcc, other.bcc) &&
MessageHelper.equal(this.reply, other.reply) &&
(this.headers == null ? other.headers == null : this.headers.equals(other.headers)) &&
(this.subject == null ? other.subject == null : this.subject.equals(other.subject)) &&
(this.size == null ? other.size == null : this.size.equals(other.size)) &&
@ -327,21 +327,4 @@ public class EntityMessage implements Serializable {
}
return false;
}
static boolean equal(Address[] a1, Address[] a2) {
if (a1 == null && a2 == null)
return true;
if (a1 == null || a2 == null)
return false;
if (a1.length != a2.length)
return false;
for (int i = 0; i < a1.length; i++)
if (!a1[i].toString().equals(a2[i].toString()))
return false;
return true;
}
}

View File

@ -1625,10 +1625,10 @@ public class FragmentCompose extends FragmentEx {
boolean dirty =
((draft.identity == null ? ident != null : !draft.identity.equals(ident)) ||
(draft.extra == null ? extra != null : !draft.extra.equals(extra)) ||
!EntityMessage.equal(draft.from, afrom) ||
!EntityMessage.equal(draft.to, ato) ||
!EntityMessage.equal(draft.cc, acc) ||
!EntityMessage.equal(draft.bcc, abcc) ||
!MessageHelper.equal(draft.from, afrom) ||
!MessageHelper.equal(draft.to, ato) ||
!MessageHelper.equal(draft.cc, acc) ||
!MessageHelper.equal(draft.bcc, abcc) ||
(draft.subject == null ? subject != null : !draft.subject.equals(subject)));
// Update draft

View File

@ -21,13 +21,11 @@ package eu.faircode.email;
import android.content.Context;
import android.text.TextUtils;
import android.util.Base64;
import android.webkit.MimeTypeMap;
import org.jsoup.Jsoup;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileReader;
@ -359,12 +357,6 @@ public class MessageHelper {
this.imessage = message;
}
MessageHelper(String raw, Session isession) throws MessagingException {
byte[] bytes = Base64.decode(raw, Base64.URL_SAFE);
InputStream is = new ByteArrayInputStream(bytes);
this.imessage = new MimeMessage(isession, is);
}
boolean getSeen() throws MessagingException {
return imessage.isSet(Flags.Flag.SEEN);
}
@ -654,12 +646,20 @@ public class MessageHelper {
return result;
}
String getRaw() throws IOException, MessagingException {
if (raw == null) {
ByteArrayOutputStream os = new ByteArrayOutputStream();
imessage.writeTo(os);
raw = Base64.encodeToString(os.toByteArray(), Base64.URL_SAFE);
}
return raw;
static boolean equal(Address[] a1, Address[] a2) {
if (a1 == null && a2 == null)
return true;
if (a1 == null || a2 == null)
return false;
if (a1.length != a2.length)
return false;
for (int i = 0; i < a1.length; i++)
if (!a1[i].toString().equals(a2[i].toString()))
return false;
return true;
}
}