Allow editing sender address

pull/146/head
M66B 6 years ago
parent 5da84fe63e
commit 2f93775420

@ -22,7 +22,6 @@ Frequently requested features:
* Badge count: there is no standard Android API for this and third party solutions might stop working anytime.
* Shortcut frequently contacted: Android [doesn't support this anymore](https://developer.android.com/guide/topics/providers/contacts-provider#ObsoleteData).
* Pull down to refresh: new messages are received in real-time, so manual refreshing is not needed, see also [this FAQ](#user-content-faq2).
* *name+extra<i></i>@example.com* style addresses: most SMTP servers, including Google's servers, strictly allow verified sender addresses only to prevent spam.
Since FairEmail is meant to be privacy friendly, the following will not be added:

File diff suppressed because it is too large Load Diff

@ -45,7 +45,7 @@ import androidx.sqlite.db.SupportSQLiteDatabase;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 25,
version = 26,
entities = {
EntityIdentity.class,
EntityAccount.class,
@ -298,6 +298,13 @@ public abstract class DB extends RoomDatabase {
db.execSQL("ALTER TABLE `account` ADD COLUMN `created` INTEGER");
}
})
.addMigrations(new Migration(25, 26) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `message` ADD COLUMN `extra` TEXT");
}
})
.build();
}

@ -76,6 +76,7 @@ public class EntityMessage implements Serializable {
@NonNull
public Long folder;
public Long identity;
public String extra; // plus
public Long replying;
public Long uid; // compose = null
public String msgid;

@ -34,6 +34,7 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.preference.PreferenceManager;
import android.provider.ContactsContract;
import android.provider.OpenableColumns;
import android.text.Html;
@ -53,6 +54,7 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.MimeTypeMap;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.FilterQueryProvider;
@ -110,6 +112,9 @@ public class FragmentCompose extends FragmentEx {
private ViewGroup view;
private Spinner spFrom;
private ImageView ivIdentityAdd;
private TextView tvExtraPrefix;
private EditText etExtra;
private TextView tvExtraSuffix;
private MultiAutoCompleteTextView etTo;
private ImageView ivToAdd;
private MultiAutoCompleteTextView etCc;
@ -123,6 +128,7 @@ public class FragmentCompose extends FragmentEx {
private BottomNavigationView bottom_navigation;
private ProgressBar pbWait;
private Group grpHeader;
private Group grpExtra;
private Group grpAddresses;
private Group grpAttachments;
@ -141,6 +147,9 @@ public class FragmentCompose extends FragmentEx {
// Get controls
spFrom = view.findViewById(R.id.spFrom);
ivIdentityAdd = view.findViewById(R.id.ivIdentityAdd);
tvExtraPrefix = view.findViewById(R.id.tvExtraPrefix);
etExtra = view.findViewById(R.id.etExtra);
tvExtraSuffix = view.findViewById(R.id.tvExtraSuffix);
etTo = view.findViewById(R.id.etTo);
ivToAdd = view.findViewById(R.id.ivToAdd);
etCc = view.findViewById(R.id.etCc);
@ -154,10 +163,26 @@ public class FragmentCompose extends FragmentEx {
bottom_navigation = view.findViewById(R.id.bottom_navigation);
pbWait = view.findViewById(R.id.pbWait);
grpHeader = view.findViewById(R.id.grpHeader);
grpExtra = view.findViewById(R.id.grpExtra);
grpAddresses = view.findViewById(R.id.grpAddresses);
grpAttachments = view.findViewById(R.id.grpAttachments);
// Wire controls
spFrom.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
EntityIdentity identity = (EntityIdentity) parent.getAdapter().getItem(position);
int at = (identity == null ? -1 : identity.email.indexOf('@'));
tvExtraPrefix.setText(at < 0 ? null : identity.email.substring(0, at) + "+");
tvExtraSuffix.setText(at < 0 ? null : identity.email.substring(at));
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
tvExtraPrefix.setText(null);
tvExtraSuffix.setText(null);
}
});
ivIdentityAdd.setOnClickListener(new View.OnClickListener() {
@Override
@ -247,7 +272,11 @@ public class FragmentCompose extends FragmentEx {
setHasOptionsMenu(true);
// Initialize
tvExtraPrefix.setText(null);
tvExtraSuffix.setText(null);
grpHeader.setVisibility(View.GONE);
grpExtra.setVisibility(View.GONE);
grpAddresses.setVisibility(View.GONE);
grpAttachments.setVisibility(View.GONE);
etBody.setVisibility(View.GONE);
@ -858,6 +887,7 @@ public class FragmentCompose extends FragmentEx {
args.putLong("id", working);
args.putInt("action", action);
args.putLong("identity", identity == null ? -1 : identity.id);
args.putString("extra", etExtra.getText().toString());
args.putString("to", etTo.getText().toString());
args.putString("cc", etCc.getText().toString());
args.putString("bcc", etBcc.getText().toString());
@ -1221,6 +1251,7 @@ public class FragmentCompose extends FragmentEx {
setSubtitle(getString(R.string.title_compose, result.account.name));
etExtra.setText(result.draft.extra);
etTo.setText(MessageHelper.getFormattedAddresses(result.draft.to, true));
etCc.setText(MessageHelper.getFormattedAddresses(result.draft.cc, true));
etBcc.setText(MessageHelper.getFormattedAddresses(result.draft.bcc, true));
@ -1256,8 +1287,11 @@ public class FragmentCompose extends FragmentEx {
getActivity().invalidateOptionsMenu();
Helper.setViewsEnabled(view, true);
boolean sender = PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean("sender", false);
pbWait.setVisibility(View.GONE);
grpHeader.setVisibility(View.VISIBLE);
grpExtra.setVisibility(sender ? View.VISIBLE : View.GONE);
grpAddresses.setVisibility("reply_all".equals(action) ? View.VISIBLE : View.GONE);
etBody.setVisibility(View.VISIBLE);
edit_bar.setVisibility(View.VISIBLE);
@ -1361,6 +1395,7 @@ public class FragmentCompose extends FragmentEx {
long id = args.getLong("id");
int action = args.getInt("action");
long iid = args.getLong("identity");
String extra = args.getString("extra");
String to = args.getString("to");
String cc = args.getString("cc");
String bcc = args.getString("bcc");
@ -1389,8 +1424,12 @@ public class FragmentCompose extends FragmentEx {
InternetAddress acc[] = (TextUtils.isEmpty(cc) ? null : InternetAddress.parse(cc));
InternetAddress abcc[] = (TextUtils.isEmpty(bcc) ? null : InternetAddress.parse(bcc));
if (TextUtils.isEmpty(extra))
extra = null;
// Update draft
draft.identity = (identity == null ? null : identity.id);
draft.extra = extra;
draft.from = afrom;
draft.to = ato;
draft.cc = acc;

@ -50,6 +50,7 @@ public class FragmentOptions extends FragmentEx {
private SwitchCompat swBrowse;
private SwitchCompat swSwipe;
private SwitchCompat swNav;
private SwitchCompat swSender;
private SwitchCompat swInsecure;
private Spinner spDownload;
private SwitchCompat swDebug;
@ -71,6 +72,7 @@ public class FragmentOptions extends FragmentEx {
swBrowse = view.findViewById(R.id.swBrowse);
swSwipe = view.findViewById(R.id.swSwipe);
swNav = view.findViewById(R.id.swNav);
swSender = view.findViewById(R.id.swSender);
swInsecure = view.findViewById(R.id.swInsecure);
spDownload = view.findViewById(R.id.spDownload);
swDebug = view.findViewById(R.id.swDebug);
@ -185,6 +187,14 @@ public class FragmentOptions extends FragmentEx {
}
});
swSender.setChecked(prefs.getBoolean("sender", true));
swSender.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("sender", checked).apply();
}
});
swInsecure.setChecked(prefs.getBoolean("insecure", false));
swInsecure.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override

@ -114,6 +114,7 @@ public class FragmentSetup extends FragmentEx {
"browse",
"swipe",
"navigation",
"sender",
"insecure",
"sort"
);

@ -183,8 +183,16 @@ public class MessageHelper {
imessage.setFlag(Flags.Flag.SEEN, message.seen);
if (message.from != null && message.from.length > 0)
imessage.setFrom(message.from[0]);
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)) {
int at = email.indexOf('@');
email = email.substring(0, at) + "+" + message.extra + email.substring(at);
Log.i(Helper.TAG, "extra=" + email);
}
imessage.setFrom(new InternetAddress(email, name));
}
if (message.to != null && message.to.length > 0)
imessage.setRecipients(Message.RecipientType.TO, message.to);

@ -35,6 +35,38 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/spFrom" />
<TextView
android:id="@+id/tvExtraPrefix"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:text="name+"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintBottom_toBottomOf="@+id/etExtra"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/etExtra" />
<EditText
android:id="@+id/etExtra"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toStartOf="@+id/tvExtraSuffix"
app:layout_constraintStart_toEndOf="@id/tvExtraPrefix"
app:layout_constraintTop_toBottomOf="@id/spFrom" />
<TextView
android:id="@+id/tvExtraSuffix"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="12dp"
android:text="\@example.com"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintBottom_toBottomOf="@+id/etExtra"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/etExtra"
app:layout_constraintTop_toTopOf="@+id/etExtra" />
<MultiAutoCompleteTextView
android:id="@+id/etTo"
android:layout_width="0dp"
@ -46,7 +78,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toStartOf="@+id/ivToAdd"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/spFrom" />
app:layout_constraintTop_toBottomOf="@id/etExtra" />
<ImageView
android:id="@+id/ivToAdd"
@ -175,6 +207,12 @@
android:layout_height="0dp"
app:constraint_referenced_ids="spFrom,ivIdentityAdd,etTo,ivToAdd,etSubject,vSeparator" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpExtra"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="tvExtraPrefix,etExtra,tvExtraSuffix" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpAddresses"
android:layout_width="0dp"

@ -92,6 +92,24 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swSwipe" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swSender"
android:layout_width="match_parent"
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/swNav" />
<TextView
android:id="@+id/tvSender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_advanced_sender_hint"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swSender" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swInsecure"
android:layout_width="match_parent"
@ -99,7 +117,7 @@
android:layout_marginTop="12dp"
android:text="@string/title_allow_insecure"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swNav" />
app:layout_constraintTop_toBottomOf="@id/tvSender" />
<TextView
android:id="@+id/tvDownload"

@ -101,6 +101,8 @@
<string name="title_advanced_browse">Browse messages on the server</string>
<string name="title_advanced_swipe">Swipe actions</string>
<string name="title_advanced_nav">Previous/next navigation</string>
<string name="title_advanced_sender">Allow editing sender address</string>
<string name="title_advanced_sender_hint">Most providers do not allow modified sender addresses</string>
<string name="title_advanced_download">Automatically download messages and attachments on a metered connection up to</string>
<string name="title_advanced_debug">Debug mode</string>

Loading…
Cancel
Save