Answer to original message text

This commit is contained in:
M66B 2020-07-13 16:34:55 +02:00
parent d23ca3a03b
commit c9cf140fe4
4 changed files with 45 additions and 0 deletions

1
FAQ.md
View File

@ -389,6 +389,7 @@ The low priority status bar notification shows the number of pending operations,
* *subscribe*: subscribe to remote folder
* *send*: send message
* *exists*: check if message exists
* *rule*: execute rule on body text
Operations are processed only when there is a connection to the email server or when manually synchronizing.
See also [this FAQ](#user-content-faq16).

View File

@ -381,6 +381,10 @@ class Core {
onSubscribeFolder(context, jargs, folder, (IMAPFolder) ifolder);
break;
case EntityOperation.RULE:
onRule(context, jargs, message);
break;
default:
throw new IllegalArgumentException("Unknown operation=" + op.name);
}
@ -1711,6 +1715,21 @@ class Core {
Log.i(folder.name + " subscribed=" + subscribe);
}
private static void onRule(Context context, JSONArray jargs, EntityMessage message) throws JSONException, IOException {
// Download message body
DB db = DB.getInstance(context);
long id = jargs.getLong(0);
EntityRule rule = db.rule().getRule(id);
if (rule == null)
throw new IllegalArgumentException("Rule not found id=" + id);
if (!message.content)
throw new IllegalArgumentException("Message without content id=" + rule.id + ":" + rule.name);
rule.execute(context, message);
}
private static void onSynchronizeMessages(
Context context, JSONArray jargs,
EntityAccount account, final EntityFolder folder,

View File

@ -98,6 +98,7 @@ public class EntityOperation {
static final String SUBSCRIBE = "subscribe";
static final String SEND = "send";
static final String EXISTS = "exists";
static final String RULE = "rule";
static void queue(Context context, EntityMessage message, String name, Object... values) {
DB db = DB.getInstance(context);

View File

@ -36,6 +36,8 @@ import androidx.room.PrimaryKey;
import org.json.JSONException;
import org.json.JSONObject;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import java.io.File;
import java.io.IOException;
@ -407,6 +409,12 @@ public class EntityRule {
}
private boolean onActionAnswer(Context context, EntityMessage message, JSONObject jargs) throws JSONException, IOException {
if (!message.content) {
EntityOperation.queue(context, message, EntityOperation.BODY);
EntityOperation.queue(context, message, EntityOperation.RULE, this.id);
return true;
}
long iid = jargs.getLong("identity");
long aid = jargs.getLong("answer");
boolean cc = (jargs.has("cc") && jargs.getBoolean("cc"));
@ -458,6 +466,22 @@ public class EntityRule {
reply.id = db.message().insertMessage(reply);
String body = answer.getText(message.from);
Document msg = JsoupEx.parse(body);
Element div = msg.createElement("div");
Element p = msg.createElement("p");
DateFormat DF = Helper.getDateTimeInstance(context);
p.text(DF.format(new Date(message.received)) + " " + MessageHelper.formatAddresses(message.from) + ":");
div.appendChild(p);
Document answering = JsoupEx.parse(message.getFile(context));
div.appendChild(answering.body().tagName("blockquote"));
msg.body().appendChild(div);
body = msg.outerHtml();
File file = reply.getFile(context);
Helper.writeText(file, body);
db.message().setMessageContent(reply.id,