Added auto CC

pull/177/head
M66B 5 years ago
parent df679874a3
commit cc8f00b846

File diff suppressed because it is too large Load Diff

@ -60,7 +60,7 @@ import io.requery.android.database.sqlite.SQLiteDatabase;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 147,
version = 148,
entities = {
EntityIdentity.class,
EntityAccount.class,
@ -1408,6 +1408,13 @@ public abstract class DB extends RoomDatabase {
Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `account` ADD COLUMN `thread` INTEGER");
}
})
.addMigrations(new Migration(147, 148) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {
Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `identity` ADD COLUMN `cc` TEXT");
}
});
}

@ -92,6 +92,7 @@ public class EntityIdentity {
public Boolean sender_extra = false;
public String sender_extra_regex;
public String replyto;
public String cc;
public String bcc;
@NonNull
public Boolean plain_only = false; // obsolete
@ -187,6 +188,7 @@ public class EntityIdentity {
json.put("sender_extra_regex", sender_extra_regex);
json.put("replyto", replyto);
json.put("cc", cc);
json.put("bcc", bcc);
// not plain_only
@ -240,6 +242,8 @@ public class EntityIdentity {
if (json.has("replyto") && !json.isNull("replyto"))
identity.replyto = json.getString("replyto");
if (json.has("cc") && !json.isNull("cc"))
identity.cc = json.getString("cc");
if (json.has("bcc") && !json.isNull("bcc"))
identity.bcc = json.getString("bcc");
@ -270,6 +274,7 @@ public class EntityIdentity {
this.sender_extra.equals(sender_extra) &&
Objects.equals(this.sender_extra_regex, other.sender_extra_regex) &&
Objects.equals(this.replyto, other.replyto) &&
Objects.equals(this.cc, other.cc) &&
Objects.equals(this.bcc, other.bcc) &&
Objects.equals(this.sign_key, other.sign_key) &&
Objects.equals(this.sign_key_alias, other.sign_key_alias) &&

@ -109,6 +109,7 @@ public class FragmentIdentity extends FragmentBase {
private CheckBox cbSenderExtra;
private TextView etSenderExtra;
private EditText etReplyTo;
private EditText etCc;
private EditText etBcc;
private Button btnSave;
@ -197,6 +198,7 @@ public class FragmentIdentity extends FragmentBase {
cbSenderExtra = view.findViewById(R.id.cbSenderExtra);
etSenderExtra = view.findViewById(R.id.etSenderExtra);
etReplyTo = view.findViewById(R.id.etReplyTo);
etCc = view.findViewById(R.id.etCc);
etBcc = view.findViewById(R.id.etBcc);
btnSave = view.findViewById(R.id.btnSave);
@ -573,6 +575,7 @@ public class FragmentIdentity extends FragmentBase {
args.putBoolean("sender_extra", cbSenderExtra.isChecked());
args.putString("sender_extra_regex", etSenderExtra.getText().toString());
args.putString("replyto", etReplyTo.getText().toString().trim());
args.putString("cc", etCc.getText().toString().trim());
args.putString("bcc", etBcc.getText().toString().trim());
args.putLong("account", account == null ? -1 : account.id);
args.putString("host", etHost.getText().toString().trim());
@ -643,6 +646,7 @@ public class FragmentIdentity extends FragmentBase {
boolean sender_extra = args.getBoolean("sender_extra");
String sender_extra_regex = args.getString("sender_extra_regex");
String replyto = args.getString("replyto");
String cc = args.getString("cc");
String bcc = args.getString("bcc");
boolean should = args.getBoolean("should");
@ -676,6 +680,14 @@ public class FragmentIdentity extends FragmentBase {
throw new IllegalArgumentException(context.getString(R.string.title_email_invalid, replyto));
}
}
if (!TextUtils.isEmpty(cc) && !should)
try {
InternetAddress.parse(cc);
} catch (AddressException ex) {
throw new IllegalArgumentException(context.getString(R.string.title_email_invalid, cc));
}
if (!TextUtils.isEmpty(bcc) && !should)
try {
InternetAddress.parse(bcc);
@ -695,6 +707,9 @@ public class FragmentIdentity extends FragmentBase {
if (TextUtils.isEmpty(replyto))
replyto = null;
if (TextUtils.isEmpty(cc))
cc = null;
if (TextUtils.isEmpty(bcc))
bcc = null;
@ -754,6 +769,8 @@ public class FragmentIdentity extends FragmentBase {
return true;
if (!Objects.equals(identity.replyto, replyto))
return true;
if (!Objects.equals(identity.cc, cc))
return true;
if (!Objects.equals(identity.bcc, bcc))
return true;
@ -831,6 +848,7 @@ public class FragmentIdentity extends FragmentBase {
identity.sender_extra = sender_extra;
identity.sender_extra_regex = sender_extra_regex;
identity.replyto = replyto;
identity.cc = cc;
identity.bcc = bcc;
identity.sent_folder = null;
identity.sign_key = null;
@ -1037,6 +1055,7 @@ public class FragmentIdentity extends FragmentBase {
cbSenderExtra.setChecked(identity != null && identity.sender_extra);
etSenderExtra.setText(identity == null ? null : identity.sender_extra_regex);
etReplyTo.setText(identity == null ? null : identity.replyto);
etCc.setText(identity == null ? null : identity.cc);
etBcc.setText(identity == null ? null : identity.bcc);
auth = (identity == null ? EmailService.AUTH_TYPE_PASSWORD : identity.auth_type);

@ -204,30 +204,13 @@ public class MessageHelper {
if (identity.replyto != null)
imessage.setReplyTo(InternetAddress.parse(identity.replyto));
// Add extra bcc
if (identity.bcc != null) {
List<Address> bcc = new ArrayList<>();
Address[] existing = imessage.getRecipients(Message.RecipientType.BCC);
if (existing != null)
bcc.addAll(Arrays.asList(existing));
Address[] all = imessage.getAllRecipients();
Address[] abccs = InternetAddress.parse(identity.bcc);
for (Address abcc : abccs) {
boolean found = false;
if (all != null)
for (Address a : all)
if (equalEmail(a, abcc)) {
found = true;
break;
}
if (!found)
bcc.add(abcc);
}
// Add extra cc
if (identity.cc != null)
addAddress(identity.cc, Message.RecipientType.CC, imessage);
imessage.setRecipients(Message.RecipientType.BCC, bcc.toArray(new Address[0]));
}
// Add extra bcc
if (identity.bcc != null)
addAddress(identity.bcc, Message.RecipientType.BCC, imessage);
// Delivery/read request
if (message.receipt_request != null && message.receipt_request) {
@ -474,6 +457,30 @@ public class MessageHelper {
return imessage;
}
private static void addAddress(String email, Message.RecipientType type, MimeMessage imessage) throws MessagingException {
List<Address> result = new ArrayList<>();
Address[] existing = imessage.getRecipients(type);
if (existing != null)
result.addAll(Arrays.asList(existing));
Address[] all = imessage.getAllRecipients();
Address[] addresses = InternetAddress.parse(email);
for (Address address : addresses) {
boolean found = false;
if (all != null)
for (Address a : all)
if (equalEmail(a, address)) {
found = true;
break;
}
if (!found)
result.add(address);
}
imessage.setRecipients(type, result.toArray(new Address[0]));
}
static void build(Context context, EntityMessage message, List<EntityAttachment> attachments, EntityIdentity identity, MimeMessage imessage) throws IOException, MessagingException {
if (message.receipt != null && message.receipt) {
// https://www.ietf.org/rfc/rfc3798.txt

@ -397,6 +397,7 @@ public class ServiceSend extends ServiceBase {
message.folder = sent.id;
message.identity = null;
message.from = helper.getFrom();
message.cc = helper.getCc();
message.bcc = helper.getBcc();
message.reply = helper.getReply();
message.received = new Date().getTime();

@ -566,6 +566,38 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvReplyTo" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvCc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_cc"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etReplyTo" />
<eu.faircode.email.EditTextPlain
android:id="@+id/etCc"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:autofillHints="emailAddress"
android:hint="@string/title_optional"
android:inputType="textEmailAddress"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvCc" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvCcHint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_advanced_bcc_hint"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="italic"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etCc" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvBcc"
android:layout_width="wrap_content"
@ -574,7 +606,7 @@
android:text="@string/title_bcc"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etReplyTo" />
app:layout_constraintTop_toBottomOf="@id/tvCcHint" />
<eu.faircode.email.EditTextPlain
android:id="@+id/etBcc"
@ -719,7 +751,7 @@
cbUseIp,tvUseIpHint,
cbSynchronize,cbPrimary,
cbSenderExtra,tvSenderExtra,etSenderExtra,tvSenderExtraHint,
tvReplyTo,etReplyTo,tvBcc,etBcc,tvBccHint" />
tvReplyTo,etReplyTo,tvCc,etCc,tvCcHint,tvBcc,etBcc,tvBccHint" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpError"

Loading…
Cancel
Save