mirror of
https://github.com/M66B/FairEmail.git
synced 2025-03-03 18:26:20 +00:00
Added create folder to rule move
This commit is contained in:
parent
dd6d2ba33b
commit
320748e689
5 changed files with 114 additions and 6 deletions
|
@ -1399,6 +1399,7 @@ class Core {
|
|||
boolean seen = jargs.optBoolean(1);
|
||||
boolean unflag = jargs.optBoolean(3);
|
||||
boolean delete = jargs.optBoolean(4);
|
||||
boolean create = jargs.optBoolean(5);
|
||||
|
||||
Flags flags = ifolder.getPermanentFlags();
|
||||
|
||||
|
@ -1411,6 +1412,20 @@ class Core {
|
|||
if (!target.selectable)
|
||||
throw new IllegalArgumentException("not selectable type=" + target.type);
|
||||
|
||||
if (create) {
|
||||
Folder icreate = istore.getFolder(target.name);
|
||||
if (!icreate.exists()) {
|
||||
((IMAPFolder) ifolder).doCommand(new IMAPFolder.ProtocolCommand() {
|
||||
@Override
|
||||
public Object doCommand(IMAPProtocol protocol) throws ProtocolException {
|
||||
protocol.create(target.name);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
ifolder.setSubscribed(true);
|
||||
}
|
||||
}
|
||||
|
||||
// De-classify
|
||||
if (!copy &&
|
||||
!EntityFolder.TRASH.equals(target.type) &&
|
||||
|
@ -2625,6 +2640,8 @@ class Core {
|
|||
folder.download = parent.download;
|
||||
folder.auto_classify_source = parent.auto_classify_source;
|
||||
folder.auto_classify_target = parent.auto_classify_target;
|
||||
folder.sync_days = parent.sync_days;
|
||||
folder.keep_days = parent.keep_days;
|
||||
folder.unified = parent.unified;
|
||||
folder.navigation = parent.navigation;
|
||||
folder.notify = parent.notify;
|
||||
|
@ -2845,7 +2862,7 @@ class Core {
|
|||
}
|
||||
}
|
||||
|
||||
private static void onRule(Context context, JSONArray jargs, EntityMessage message) throws JSONException, IOException, AddressException {
|
||||
private static void onRule(Context context, JSONArray jargs, EntityMessage message) throws JSONException, MessagingException {
|
||||
// Download message body
|
||||
DB db = DB.getInstance(context);
|
||||
|
||||
|
|
|
@ -609,18 +609,71 @@ public class EntityRule {
|
|||
|
||||
private boolean onActionMove(Context context, EntityMessage message, JSONObject jargs) {
|
||||
long target = jargs.optLong("target", -1);
|
||||
String create = jargs.optString("create");
|
||||
boolean seen = jargs.optBoolean("seen");
|
||||
boolean thread = jargs.optBoolean("thread");
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
|
||||
EntityFolder folder = db.folder().getFolder(target);
|
||||
if (folder == null)
|
||||
throw new IllegalArgumentException("Rule move to folder not found name=" + name);
|
||||
|
||||
if (!TextUtils.isEmpty(create)) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
String year = String.format(Locale.ROOT, "%04d", calendar.get(Calendar.YEAR));
|
||||
String month = String.format(Locale.ROOT, "%02d", calendar.get(Calendar.MONTH) + 1);
|
||||
|
||||
create = create.replace("$year$", year);
|
||||
create = create.replace("$month$", month);
|
||||
|
||||
String domain = "";
|
||||
if (message.from != null &&
|
||||
message.from.length > 0 &&
|
||||
message.from[0] instanceof InternetAddress) {
|
||||
InternetAddress from = (InternetAddress) message.from[0];
|
||||
domain = UriHelper.getEmailDomain(from.getAddress());
|
||||
}
|
||||
create = create.replace("$domain$", domain);
|
||||
|
||||
String name = folder.name + folder.separator + create;
|
||||
EntityFolder created = db.folder().getFolderByName(message.account, name);
|
||||
if (created == null) {
|
||||
created = new EntityFolder();
|
||||
created.tbc = true;
|
||||
created.account = folder.account;
|
||||
created.namespace = folder.namespace;
|
||||
created.separator = folder.separator;
|
||||
created.name = name;
|
||||
created.type = EntityFolder.USER;
|
||||
created.subscribed = true;
|
||||
created.setProperties();
|
||||
|
||||
EntityAccount account = db.account().getAccount(folder.account);
|
||||
created.setSpecials(account);
|
||||
|
||||
created.synchronize = folder.synchronize;
|
||||
created.poll = folder.poll;
|
||||
created.poll_factor = folder.poll_factor;
|
||||
created.download = folder.download;
|
||||
created.auto_classify_source = folder.auto_classify_source;
|
||||
created.auto_classify_target = folder.auto_classify_target;
|
||||
created.sync_days = folder.sync_days;
|
||||
created.keep_days = folder.keep_days;
|
||||
created.unified = folder.unified;
|
||||
created.navigation = folder.navigation;
|
||||
created.notify = folder.notify;
|
||||
|
||||
created.id = db.folder().insertFolder(created);
|
||||
}
|
||||
target = created.id;
|
||||
}
|
||||
|
||||
List<EntityMessage> messages = db.message().getMessagesByThread(
|
||||
message.account, message.thread, thread ? null : message.id, message.folder);
|
||||
for (EntityMessage threaded : messages)
|
||||
EntityOperation.queue(context, threaded, EntityOperation.MOVE, target, seen, null, true);
|
||||
EntityOperation.queue(context, threaded, EntityOperation.MOVE, target,
|
||||
seen, null, true, false, !TextUtils.isEmpty(create));
|
||||
|
||||
message.ui_hide = true;
|
||||
|
||||
|
|
|
@ -136,6 +136,7 @@ public class FragmentRule extends FragmentBase {
|
|||
private EditText etKeyword;
|
||||
|
||||
private Button btnFolder;
|
||||
private EditText etMoveCreate;
|
||||
private CheckBox cbMoveSeen;
|
||||
private CheckBox cbMoveThread;
|
||||
|
||||
|
@ -290,6 +291,7 @@ public class FragmentRule extends FragmentBase {
|
|||
etKeyword = view.findViewById(R.id.etKeyword);
|
||||
|
||||
btnFolder = view.findViewById(R.id.btnFolder);
|
||||
etMoveCreate = view.findViewById(R.id.etMoveCreate);
|
||||
cbMoveSeen = view.findViewById(R.id.cbMoveSeen);
|
||||
cbMoveThread = view.findViewById(R.id.cbMoveThread);
|
||||
|
||||
|
@ -1170,6 +1172,7 @@ public class FragmentRule extends FragmentBase {
|
|||
long target = jaction.optLong("target", -1);
|
||||
showFolder(target);
|
||||
if (type == EntityRule.TYPE_MOVE) {
|
||||
etMoveCreate.setText(jaction.optString("create"));
|
||||
cbMoveSeen.setChecked(jaction.optBoolean("seen"));
|
||||
cbMoveThread.setChecked(jaction.optBoolean("thread"));
|
||||
}
|
||||
|
@ -1525,6 +1528,7 @@ public class FragmentRule extends FragmentBase {
|
|||
Object tag = btnFolder.getTag();
|
||||
jaction.put("target", tag instanceof Long ? (long) tag : -1);
|
||||
if (action.type == EntityRule.TYPE_MOVE) {
|
||||
jaction.put("create", etMoveCreate.getText().toString().trim());
|
||||
jaction.put("seen", cbMoveSeen.isChecked());
|
||||
jaction.put("thread", cbMoveThread.isChecked());
|
||||
}
|
||||
|
|
|
@ -786,6 +786,37 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvMoveTarget" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvMoveCreate"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_rule_folder_create"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/btnFolder" />
|
||||
|
||||
<eu.faircode.email.EditTextPlain
|
||||
android:id="@+id/etMoveCreate"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/title_optional"
|
||||
android:inputType="text"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvMoveCreate" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvMoveCreateRemark"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="$year$ $month$ $domain$"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:textStyle="italic"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/etMoveCreate" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/cbMoveSeen"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -793,7 +824,7 @@
|
|||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_rule_seen"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/btnFolder" />
|
||||
app:layout_constraintTop_toBottomOf="@id/tvMoveCreateRemark" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/cbMoveThread"
|
||||
|
@ -873,7 +904,6 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:hint="@string/title_optional"
|
||||
android:text="@string/title_rule_forward_to"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
@ -883,6 +913,7 @@
|
|||
android:id="@+id/etTo"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/title_optional"
|
||||
android:inputType="textEmailAddress"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
app:layout_constraintEnd_toStartOf="@+id/ibTo"
|
||||
|
@ -992,6 +1023,7 @@
|
|||
android:layout_marginTop="6dp"
|
||||
android:text="@string/title_rule_alarm_hint"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:textStyle="italic"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/cbAlarm" />
|
||||
|
||||
|
@ -1026,6 +1058,7 @@
|
|||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_rule_automation_hint"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:textStyle="italic"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/etAlarmDuration" />
|
||||
|
||||
|
@ -1036,11 +1069,11 @@
|
|||
android:layout_marginTop="12dp"
|
||||
android:drawableStart="@drawable/twotone_warning_24"
|
||||
android:drawablePadding="6dp"
|
||||
app:drawableTint="?attr/colorWarning"
|
||||
android:text="@string/title_rule_delete_hint"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
android:textColor="?attr/colorWarning"
|
||||
android:textStyle="bold"
|
||||
app:drawableTint="?attr/colorWarning"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/tvAutomation" />
|
||||
|
||||
|
@ -1096,7 +1129,7 @@
|
|||
android:id="@+id/grpMoveProp"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:constraint_referenced_ids="cbMoveSeen,cbMoveThread" />
|
||||
app:constraint_referenced_ids="tvMoveCreate,etMoveCreate,tvMoveCreateRemark,cbMoveSeen,cbMoveThread" />
|
||||
|
||||
<androidx.constraintlayout.widget.Group
|
||||
android:id="@+id/grpAnswer"
|
||||
|
|
|
@ -1728,6 +1728,7 @@
|
|||
<string name="title_rule_hours">Hours</string>
|
||||
<string name="title_rule_schedule_end">From the end of the time condition</string>
|
||||
<string name="title_rule_folder">Folder</string>
|
||||
<string name="title_rule_folder_create">Create subfolder</string>
|
||||
<string name="title_rule_thread">All messages in same conversation and folder</string>
|
||||
<string name="title_rule_identity">Identity</string>
|
||||
<string name="title_rule_template">Reply template</string>
|
||||
|
|
Loading…
Reference in a new issue