Added identity option to send plain text only

pull/147/head
M66B 6 years ago
parent aa3f4a4990
commit f0fc21bfbc

File diff suppressed because it is too large Load Diff

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

@ -76,6 +76,8 @@ public class EntityIdentity {
public String replyto; public String replyto;
public String bcc; public String bcc;
@NonNull @NonNull
public Boolean plain_only = false;
@NonNull
public Boolean delivery_receipt = false; public Boolean delivery_receipt = false;
@NonNull @NonNull
public Boolean read_receipt = false; public Boolean read_receipt = false;
@ -113,6 +115,7 @@ public class EntityIdentity {
json.put("replyto", replyto); json.put("replyto", replyto);
json.put("bcc", bcc); json.put("bcc", bcc);
json.put("plain_only", plain_only);
json.put("delivery_receipt", delivery_receipt); json.put("delivery_receipt", delivery_receipt);
json.put("read_receipt", read_receipt); json.put("read_receipt", read_receipt);
json.put("store_sent", store_sent); json.put("store_sent", store_sent);
@ -151,6 +154,8 @@ public class EntityIdentity {
if (json.has("bcc")) if (json.has("bcc"))
identity.bcc = json.getString("bcc"); identity.bcc = json.getString("bcc");
if (json.has("plain_only"))
identity.plain_only = json.getBoolean("plain_only");
if (json.has("delivery_receipt")) if (json.has("delivery_receipt"))
identity.delivery_receipt = json.getBoolean("delivery_receipt"); identity.delivery_receipt = json.getBoolean("delivery_receipt");
if (json.has("read_receipt")) if (json.has("read_receipt"))

@ -1003,11 +1003,14 @@ public class FragmentCompose extends FragmentBase {
if (attachment.encryption != null) if (attachment.encryption != null)
attachments.remove(attachment); attachments.remove(attachment);
EntityIdentity identity =
(message.identity == null ? null : db.identity().getIdentity(message.identity));
// Build message // Build message
Properties props = MessageHelper.getSessionProperties(Helper.AUTH_TYPE_PASSWORD, null, false); Properties props = MessageHelper.getSessionProperties(Helper.AUTH_TYPE_PASSWORD, null, false);
Session isession = Session.getInstance(props, null); Session isession = Session.getInstance(props, null);
MimeMessage imessage = new MimeMessage(isession); MimeMessage imessage = new MimeMessage(isession);
MessageHelper.build(context, message, imessage); MessageHelper.build(context, message, imessage, identity == null ? false : identity.plain_only);
// Serialize message // Serialize message
ByteArrayOutputStream os = new ByteArrayOutputStream(); ByteArrayOutputStream os = new ByteArrayOutputStream();

@ -99,6 +99,7 @@ public class FragmentIdentity extends FragmentBase {
private EditText etReplyTo; private EditText etReplyTo;
private EditText etBcc; private EditText etBcc;
private CheckBox cbPlainOnly;
private CheckBox cbDeliveryReceipt; private CheckBox cbDeliveryReceipt;
private CheckBox cbReadReceipt; private CheckBox cbReadReceipt;
@ -165,6 +166,7 @@ public class FragmentIdentity extends FragmentBase {
etReplyTo = view.findViewById(R.id.etReplyTo); etReplyTo = view.findViewById(R.id.etReplyTo);
etBcc = view.findViewById(R.id.etBcc); etBcc = view.findViewById(R.id.etBcc);
cbPlainOnly = view.findViewById(R.id.cbPlainOnly);
cbDeliveryReceipt = view.findViewById(R.id.cbDeliveryReceipt); cbDeliveryReceipt = view.findViewById(R.id.cbDeliveryReceipt);
cbReadReceipt = view.findViewById(R.id.cbReadReceipt); cbReadReceipt = view.findViewById(R.id.cbReadReceipt);
@ -464,6 +466,7 @@ public class FragmentIdentity extends FragmentBase {
args.putString("display", etDisplay.getText().toString()); args.putString("display", etDisplay.getText().toString());
args.putString("replyto", etReplyTo.getText().toString().trim()); args.putString("replyto", etReplyTo.getText().toString().trim());
args.putString("bcc", etBcc.getText().toString().trim()); args.putString("bcc", etBcc.getText().toString().trim());
args.putBoolean("plain_only", cbPlainOnly.isChecked());
args.putBoolean("delivery_receipt", cbDeliveryReceipt.isChecked()); args.putBoolean("delivery_receipt", cbDeliveryReceipt.isChecked());
args.putBoolean("read_receipt", cbReadReceipt.isChecked()); args.putBoolean("read_receipt", cbReadReceipt.isChecked());
args.putBoolean("store_sent", cbStoreSent.isChecked()); args.putBoolean("store_sent", cbStoreSent.isChecked());
@ -523,6 +526,7 @@ public class FragmentIdentity extends FragmentBase {
String replyto = args.getString("replyto"); String replyto = args.getString("replyto");
String bcc = args.getString("bcc"); String bcc = args.getString("bcc");
boolean plain_only = args.getBoolean("plain_only");
boolean delivery_receipt = args.getBoolean("delivery_receipt"); boolean delivery_receipt = args.getBoolean("delivery_receipt");
boolean read_receipt = args.getBoolean("read_receipt"); boolean read_receipt = args.getBoolean("read_receipt");
boolean store_sent = args.getBoolean("store_sent"); boolean store_sent = args.getBoolean("store_sent");
@ -627,6 +631,7 @@ public class FragmentIdentity extends FragmentBase {
identity.replyto = replyto; identity.replyto = replyto;
identity.bcc = bcc; identity.bcc = bcc;
identity.plain_only = plain_only;
identity.delivery_receipt = delivery_receipt; identity.delivery_receipt = delivery_receipt;
identity.read_receipt = read_receipt; identity.read_receipt = read_receipt;
identity.store_sent = store_sent; identity.store_sent = store_sent;
@ -728,6 +733,7 @@ public class FragmentIdentity extends FragmentBase {
etReplyTo.setText(identity == null ? null : identity.replyto); etReplyTo.setText(identity == null ? null : identity.replyto);
etBcc.setText(identity == null ? null : identity.bcc); etBcc.setText(identity == null ? null : identity.bcc);
cbPlainOnly.setChecked(identity == null ? false : identity.plain_only);
cbDeliveryReceipt.setChecked(identity == null ? false : identity.delivery_receipt); cbDeliveryReceipt.setChecked(identity == null ? false : identity.delivery_receipt);
cbReadReceipt.setChecked(identity == null ? false : identity.read_receipt); cbReadReceipt.setChecked(identity == null ? false : identity.read_receipt);
cbStoreSent.setChecked(identity == null ? false : identity.store_sent); cbStoreSent.setChecked(identity == null ? false : identity.store_sent);

@ -185,7 +185,7 @@ public class MessageHelper {
return props; return props;
} }
static MimeMessageEx from(Context context, EntityMessage message, Session isession) throws MessagingException, IOException { static MimeMessageEx from(Context context, EntityMessage message, Session isession, boolean plainOnly) throws MessagingException, IOException {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
MimeMessageEx imessage = new MimeMessageEx(isession, message.msgid); MimeMessageEx imessage = new MimeMessageEx(isession, message.msgid);
@ -282,12 +282,12 @@ public class MessageHelper {
return imessage; return imessage;
} }
build(context, message, imessage); build(context, message, imessage, plainOnly);
return imessage; return imessage;
} }
static void build(Context context, EntityMessage message, MimeMessage imessage) throws IOException, MessagingException { static void build(Context context, EntityMessage message, MimeMessage imessage, boolean plainOnly) throws IOException, MessagingException {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
StringBuilder body = new StringBuilder(); StringBuilder body = new StringBuilder();
@ -334,11 +334,17 @@ public class MessageHelper {
Log.i("Attachments available=" + available); Log.i("Attachments available=" + available);
if (available == 0) if (available == 0)
if (plainOnly)
imessage.setContent(plainContent, "text/plain; charset=" + Charset.defaultCharset().name());
else
imessage.setContent(alternativePart); imessage.setContent(alternativePart);
else { else {
Multipart mixedPart = new MimeMultipart("mixed"); Multipart mixedPart = new MimeMultipart("mixed");
BodyPart attachmentPart = new MimeBodyPart(); BodyPart attachmentPart = new MimeBodyPart();
if (plainOnly)
attachmentPart.setContent(plainContent, "text/plain; charset=" + Charset.defaultCharset().name());
else
attachmentPart.setContent(alternativePart); attachmentPart.setContent(alternativePart);
mixedPart.addBodyPart(attachmentPart); mixedPart.addBodyPart(attachmentPart);

@ -1690,12 +1690,16 @@ public class ServiceSynchronize extends LifecycleService {
if (!message.content) if (!message.content)
throw new IllegalArgumentException("Message body missing"); throw new IllegalArgumentException("Message body missing");
EntityIdentity identity =
(message.identity == null ? null : db.identity().getIdentity(message.identity));
List<EntityAttachment> attachments = db.attachment().getAttachments(message.id); List<EntityAttachment> attachments = db.attachment().getAttachments(message.id);
for (EntityAttachment attachment : attachments) for (EntityAttachment attachment : attachments)
if (!attachment.available) if (!attachment.available)
throw new IllegalArgumentException("Attachment missing"); throw new IllegalArgumentException("Attachment missing");
imessage = MessageHelper.from(this, message, isession); imessage = MessageHelper.from(this, message, isession,
identity == null ? false : identity.plain_only);
} else { } else {
// Cross account move // Cross account move
File file = EntityMessage.getRawFile(this, message.id); File file = EntityMessage.getRawFile(this, message.id);
@ -1891,7 +1895,7 @@ public class ServiceSynchronize extends LifecycleService {
final Session isession = Session.getInstance(props, null); final Session isession = Session.getInstance(props, null);
// Create message // Create message
MimeMessage imessage = MessageHelper.from(this, message, isession); MimeMessage imessage = MessageHelper.from(this, message, isession, ident.plain_only);
// Add reply to // Add reply to
if (ident.replyto != null) if (ident.replyto != null)

@ -448,6 +448,15 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvBcc" /> app:layout_constraintTop_toBottomOf="@id/tvBcc" />
<CheckBox
android:id="@+id/cbPlainOnly"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_identity_plain_text"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etBcc" />
<CheckBox <CheckBox
android:id="@+id/cbDeliveryReceipt" android:id="@+id/cbDeliveryReceipt"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -455,7 +464,7 @@
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:text="@string/title_identity_delivery_receipt" android:text="@string/title_identity_delivery_receipt"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etBcc" /> app:layout_constraintTop_toBottomOf="@id/cbPlainOnly" />
<CheckBox <CheckBox
android:id="@+id/cbReadReceipt" android:id="@+id/cbReadReceipt"
@ -562,7 +571,7 @@
tvRealm,etRealm, tvRealm,etRealm,
cbSynchronize,cbPrimary, cbSynchronize,cbPrimary,
tvReplyTo,etReplyTo,tvBcc,etBcc, tvReplyTo,etReplyTo,tvBcc,etBcc,
cbDeliveryReceipt,cbReadReceipt,tvReceipt, cbPlainOnly,cbDeliveryReceipt,cbReadReceipt,tvReceipt,
cbStoreSent,tvStoreSent" /> cbStoreSent,tvStoreSent" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView> </ScrollView>

@ -191,6 +191,7 @@
<string name="title_identity_name">Your name</string> <string name="title_identity_name">Your name</string>
<string name="title_identity_email">Your email address</string> <string name="title_identity_email">Your email address</string>
<string name="title_identity_reply_to">Reply to address</string> <string name="title_identity_reply_to">Reply to address</string>
<string name="title_identity_plain_text">Send plain text only</string>
<string name="title_identity_read_receipt">Request read receipt</string> <string name="title_identity_read_receipt">Request read receipt</string>
<string name="title_identity_delivery_receipt">Request delivery receipt</string> <string name="title_identity_delivery_receipt">Request delivery receipt</string>
<string name="title_identity_receipt_remark">Most providers ignore receipt requests</string> <string name="title_identity_receipt_remark">Most providers ignore receipt requests</string>

Loading…
Cancel
Save