() {
@Override
protected EntityMessage onLoad(Context context, Bundle args) throws IOException {
@@ -594,7 +608,14 @@ public class FragmentCompose extends FragmentEx {
return draft;
EntityMessage ref = db.message().getMessage(reference);
- if (ref != null) {
+ if (ref == null) {
+ if (account < 0) {
+ EntityAccount a = db.account().getPrimaryAccount();
+ if (a == null)
+ throw new IllegalArgumentException(context.getString(R.string.title_no_account));
+ account = a.id;
+ }
+ } else {
account = ref.account;
// Reply to sender, not to known self
@@ -626,7 +647,34 @@ public class FragmentCompose extends FragmentEx {
draft.folder = drafts.id;
draft.msgid = EntityMessage.generateMessageId(); // for multiple appends
- if (ref != null) {
+ if (ref == null) {
+ try {
+ String to = args.getString("to");
+ draft.to = (TextUtils.isEmpty(to) ? null : InternetAddress.parse(to));
+ } catch (AddressException ex) {
+ Log.w(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
+ }
+
+ try {
+ String cc = args.getString("cc");
+ draft.cc = (TextUtils.isEmpty(cc) ? null : InternetAddress.parse(cc));
+ } catch (AddressException ex) {
+ Log.w(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
+ }
+
+ try {
+ String bcc = args.getString("bcc");
+ draft.bcc = (TextUtils.isEmpty(bcc) ? null : InternetAddress.parse(bcc));
+ } catch (AddressException ex) {
+ Log.w(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
+ }
+
+ draft.subject = args.getString("subject");
+ body = args.getString("body");
+ if (!TextUtils.isEmpty(body))
+ body = "" + body.replaceAll("\\r?\\n", "
") + "
";
+
+ } else {
draft.thread = ref.thread;
if ("reply".equals(action) || "reply_all".equals(action)) {
@@ -656,16 +704,19 @@ public class FragmentCompose extends FragmentEx {
}
}
- if ("new".equals(action))
- body = "";
-
draft.received = new Date().getTime();
draft.seen = false;
draft.ui_seen = false;
draft.ui_hide = false;
draft.id = db.message().insertMessage(draft);
- draft.write(context, body);
+ draft.write(context, body == null ? "" : body);
+
+ if (args.containsKey("attachments")) {
+ ArrayList uris = args.getParcelableArrayList("attachments");
+ for (Uri uri : uris)
+ addAttachment(context, draft.id, uri);
+ }
EntityOperation.queue(db, draft, EntityOperation.ADD);