Edit sender address per identity

pull/155/head
M66B 5 years ago
parent 3fe361c898
commit 35e3604e80

File diff suppressed because it is too large Load Diff

@ -424,8 +424,7 @@ class Core {
EntityIdentity identity =
(message.identity == null ? null : db.identity().getIdentity(message.identity));
imessage = MessageHelper.from(context, message, isession,
identity == null ? false : identity.plain_only);
imessage = MessageHelper.from(context, message, identity, isession);
} else {
// Cross account move
File file = message.getRawFile(context);

@ -50,7 +50,7 @@ import io.requery.android.database.sqlite.RequerySQLiteOpenHelperFactory;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 64,
version = 65,
entities = {
EntityIdentity.class,
EntityAccount.class,
@ -694,6 +694,13 @@ public abstract class DB extends RoomDatabase {
db.execSQL("ALTER TABLE `message` ADD COLUMN `dmarc` INTEGER");
}
})
.addMigrations(new Migration(64, 65) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `identity` ADD COLUMN `sender_extra` INTEGER NOT NULL DEFAULT 0");
}
})
.build();
}

@ -77,6 +77,8 @@ public class EntityIdentity {
public Boolean synchronize;
@NonNull
public Boolean primary;
@NonNull
public boolean sender_extra = false;
public String replyto;
public String bcc;
@NonNull

@ -177,7 +177,6 @@ public class FragmentCompose extends FragmentBase {
private boolean autosave = false;
private boolean busy = false;
private boolean sender_extra = false;
private boolean prefix_once = false;
private boolean monospaced = false;
private boolean style = true;
@ -193,7 +192,6 @@ public class FragmentCompose extends FragmentBase {
pro = Helper.isPro(getContext());
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
sender_extra = prefs.getBoolean("sender", false);
prefix_once = prefs.getBoolean("prefix_once", false);
monospaced = prefs.getBoolean("monospaced", false);
style = prefs.getBoolean("style_toolbar", true);
@ -246,6 +244,7 @@ public class FragmentCompose extends FragmentBase {
int at = (identity == null ? -1 : identity.email.indexOf('@'));
etExtra.setHint(at < 0 ? null : identity.email.substring(0, at));
tvDomain.setText(at < 0 ? null : identity.email.substring(at));
grpExtra.setVisibility(identity != null && identity.sender_extra ? View.VISIBLE : View.GONE);
Spanned signature = null;
if (pro) {
@ -1157,7 +1156,7 @@ public class FragmentCompose extends FragmentBase {
Properties props = MessageHelper.getSessionProperties(Helper.AUTH_TYPE_PASSWORD, null, false);
Session isession = Session.getInstance(props, null);
MimeMessage imessage = new MimeMessage(isession);
MessageHelper.build(context, message, imessage, identity == null ? false : identity.plain_only);
MessageHelper.build(context, message, identity, imessage);
// Serialize message
ByteArrayOutputStream os = new ByteArrayOutputStream();
@ -1712,6 +1711,13 @@ public class FragmentCompose extends FragmentBase {
body = EntityAnswer.getAnswerText(db, answer, null) + body;
} else {
if ("reply".equals(action) || "reply_all".equals(action)) {
if (ref.to != null && ref.to.length > 0) {
String to = ((InternetAddress) ref.to[0]).getAddress();
int at = to.indexOf('@');
if (at > 0)
draft.extra = to.substring(0, at);
}
draft.references = (ref.references == null ? "" : ref.references + " ") + ref.msgid;
draft.inreplyto = ref.msgid;
draft.thread = ref.thread;
@ -1909,7 +1915,6 @@ public class FragmentCompose extends FragmentBase {
etSubject.setTag(reference < 0 ? "" : etSubject.getText().toString());
grpHeader.setVisibility(View.VISIBLE);
grpExtra.setVisibility(sender_extra ? View.VISIBLE : View.GONE);
grpAddresses.setVisibility("reply_all".equals(action) ? View.VISIBLE : View.GONE);
getActivity().invalidateOptionsMenu();

@ -101,6 +101,7 @@ public class FragmentIdentity extends FragmentBase {
private CheckBox cbSynchronize;
private CheckBox cbPrimary;
private CheckBox cbSenderExtra;
private EditText etReplyTo;
private EditText etBcc;
private CheckBox cbPlainOnly;
@ -171,6 +172,7 @@ public class FragmentIdentity extends FragmentBase {
cbSynchronize = view.findViewById(R.id.cbSynchronize);
cbPrimary = view.findViewById(R.id.cbPrimary);
cbSenderExtra = view.findViewById(R.id.cbSenderExtra);
etReplyTo = view.findViewById(R.id.etReplyTo);
etBcc = view.findViewById(R.id.etBcc);
cbPlainOnly = view.findViewById(R.id.cbPlainOnly);
@ -494,6 +496,7 @@ public class FragmentIdentity extends FragmentBase {
args.putString("name", name);
args.putString("email", etEmail.getText().toString().trim());
args.putString("display", etDisplay.getText().toString());
args.putBoolean("sender_extra", cbSenderExtra.isChecked());
args.putString("replyto", etReplyTo.getText().toString().trim());
args.putString("bcc", etBcc.getText().toString().trim());
args.putBoolean("plain_only", cbPlainOnly.isChecked());
@ -557,6 +560,7 @@ public class FragmentIdentity extends FragmentBase {
boolean synchronize = args.getBoolean("synchronize");
boolean primary = args.getBoolean("primary");
boolean sender_extra = args.getBoolean("sender_extra");
String replyto = args.getString("replyto");
String bcc = args.getString("bcc");
boolean plain_only = args.getBoolean("plain_only");
@ -683,6 +687,7 @@ public class FragmentIdentity extends FragmentBase {
identity.synchronize = synchronize;
identity.primary = (identity.synchronize && primary);
identity.sender_extra = sender_extra;
identity.replyto = replyto;
identity.bcc = bcc;
identity.plain_only = plain_only;
@ -789,6 +794,7 @@ public class FragmentIdentity extends FragmentBase {
cbSynchronize.setChecked(identity == null ? true : identity.synchronize);
cbPrimary.setChecked(identity == null ? true : identity.primary);
cbSenderExtra.setChecked(identity != null && identity.sender_extra);
etReplyTo.setText(identity == null ? null : identity.replyto);
etBcc.setText(identity == null ? null : identity.bcc);
cbPlainOnly.setChecked(identity == null ? false : identity.plain_only);

@ -97,7 +97,6 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
private SwitchCompat swAutoResize;
private Spinner spAutoResize;
private TextView tvAutoResize;
private SwitchCompat swSender;
private SwitchCompat swPrefixOnce;
private SwitchCompat swAutoSend;
@ -129,7 +128,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
"startup", "date", "threading", "avatars", "identicons", "name_email", "subject_italic", "flags", "preview",
"addresses", "monospaced", "autohtml", "autoimages", "actionbar",
"pull", "swipenav", "autoexpand", "autoclose", "autonext", "collapse", "autoread", "automove",
"autoresize", "resize", "sender", "prefix_once", "autosend",
"autoresize", "resize", "prefix_once", "autosend",
"notify_preview", "search_local", "light", "sound",
"authentication", "paranoid", "english", "updates", "debug",
"first", "why", "last_update_check", "app_support", "message_swipe", "message_select", "folder_actions", "folder_sync",
@ -180,7 +179,6 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
swAutoResize = view.findViewById(R.id.swAutoResize);
spAutoResize = view.findViewById(R.id.spAutoResize);
tvAutoResize = view.findViewById(R.id.tvAutoResize);
swSender = view.findViewById(R.id.swSender);
swPrefixOnce = view.findViewById(R.id.swPrefixOnce);
swAutoSend = view.findViewById(R.id.swAutoSend);
@ -497,13 +495,6 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
}
});
swSender.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("sender", checked).apply();
}
});
swPrefixOnce.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -689,7 +680,6 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
}
spAutoResize.setEnabled(swAutoResize.isChecked());
swSender.setChecked(prefs.getBoolean("sender", false));
swPrefixOnce.setChecked(prefs.getBoolean("prefix_once", false));
swAutoSend.setChecked(!prefs.getBoolean("autosend", false));

@ -189,7 +189,8 @@ public class MessageHelper {
return props;
}
static MimeMessageEx from(Context context, EntityMessage message, Session isession, boolean plainOnly) throws MessagingException, IOException {
static MimeMessageEx from(Context context, EntityMessage message, EntityIdentity identity, Session isession)
throws MessagingException, IOException {
DB db = DB.getInstance(context);
MimeMessageEx imessage = new MimeMessageEx(isession, message.msgid);
@ -208,7 +209,7 @@ public class MessageHelper {
if (message.from != null && message.from.length > 0) {
String email = ((InternetAddress) message.from[0]).getAddress();
String name = ((InternetAddress) message.from[0]).getPersonal();
if (email != null && !TextUtils.isEmpty(message.extra)) {
if (email != null && identity != null && identity.sender_extra && !TextUtils.isEmpty(message.extra)) {
int at = email.indexOf('@');
email = message.extra + email.substring(at);
Log.i("extra=" + email);
@ -282,22 +283,19 @@ public class MessageHelper {
return imessage;
}
build(context, message, imessage, plainOnly);
build(context, message, identity, imessage);
return imessage;
}
static void build(Context context, EntityMessage message, MimeMessage imessage, boolean plainOnly) throws IOException, MessagingException {
static void build(Context context, EntityMessage message, EntityIdentity identity, MimeMessage imessage) throws IOException, MessagingException {
DB db = DB.getInstance(context);
StringBuilder body = new StringBuilder();
body.append(Helper.readText(message.getFile(context)));
if (message.identity != null) {
EntityIdentity identity = db.identity().getIdentity(message.identity);
if (!TextUtils.isEmpty(identity.signature))
body.append(identity.signature);
}
if (identity != null && !TextUtils.isEmpty(identity.signature))
body.append(identity.signature);
File refFile = message.getRefFile(context);
if (refFile.exists())
@ -334,7 +332,7 @@ public class MessageHelper {
Log.i("Attachments available=" + available);
if (available == 0)
if (plainOnly)
if (identity != null && identity.plain_only)
imessage.setContent(plainContent, "text/plain; charset=" + Charset.defaultCharset().name());
else
imessage.setContent(alternativePart);
@ -342,7 +340,7 @@ public class MessageHelper {
Multipart mixedPart = new MimeMultipart("mixed");
BodyPart attachmentPart = new MimeBodyPart();
if (plainOnly)
if (identity != null && identity.plain_only)
attachmentPart.setContent(plainContent, "text/plain; charset=" + Charset.defaultCharset().name());
else
attachmentPart.setContent(alternativePart);

@ -286,7 +286,7 @@ public class ServiceSend extends LifecycleService {
isession.setDebug(debug);
// Create message
MimeMessage imessage = MessageHelper.from(this, message, isession, ident.plain_only);
MimeMessage imessage = MessageHelper.from(this, message, ident, isession);
// Add reply to
if (ident.replyto != null)

@ -437,6 +437,25 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbSynchronize" />
<CheckBox
android:id="@+id/cbSenderExtra"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_sender"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbPrimary" />
<TextView
android:id="@+id/tvSenderExtraHint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_advanced_sender_hint"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="italic"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbSenderExtra" />
<!-- reply to -->
<TextView
@ -447,7 +466,7 @@
android:text="@string/title_identity_reply_to"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbPrimary" />
app:layout_constraintTop_toBottomOf="@id/tvSenderExtraHint" />
<EditText
android:id="@+id/etReplyTo"
@ -613,6 +632,7 @@
tvRealm,etRealm,
cbUseIp,tvUseIpHint,
cbSynchronize,cbPrimary,
cbSenderExtra,tvSenderExtraHint,
tvReplyTo,etReplyTo,tvBcc,etBcc,
cbPlainOnly,cbEncrypt,cbDeliveryReceipt,cbReadReceipt,tvReceipt,
cbStoreSent,tvStoreSent" />

@ -676,31 +676,6 @@
app:layout_constraintStart_toEndOf="@id/spAutoResize"
app:layout_constraintTop_toTopOf="@id/spAutoResize" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swSender"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="12dp"
android:text="@string/title_advanced_sender"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/spAutoResize"
app:switchPadding="12dp" />
<TextView
android:id="@+id/tvSenderHint"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginEnd="60dp"
android:text="@string/title_advanced_sender_hint"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swSender" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swPrefixOnce"
android:layout_width="match_parent"
@ -710,7 +685,7 @@
android:layout_marginEnd="12dp"
android:text="@string/title_advanced_prefix_once"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvSenderHint"
app:layout_constraintTop_toBottomOf="@id/spAutoResize"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat

Loading…
Cancel
Save