MCPcopy Create free account
hub / github.com/M66B/FairEmail / answer

Method answer

app/src/main/java/eu/faircode/email/EntityRule.java:1116–1288  ·  view source on GitHub ↗
(Context context, EntityRule rule, EntityMessage message, JSONObject jargs)

Source from the content-addressed store, hash-verified

1114 }
1115
1116 private static void answer(Context context, EntityRule rule, EntityMessage message, JSONObject jargs) throws JSONException, AddressException, IOException {
1117 Log.i("Answering name=" + rule.name);
1118
1119 DB db = DB.getInstance(context);
1120
1121 long iid = jargs.getLong("identity");
1122 long aid = jargs.getLong("answer");
1123 boolean answer_subject = jargs.optBoolean("answer_subject", false);
1124 boolean original_text = jargs.optBoolean("original_text", true);
1125 boolean attachments = jargs.optBoolean("attachments");
1126 String to = jargs.optString("to");
1127 boolean resend = jargs.optBoolean("resend");
1128 boolean attached = jargs.optBoolean("attached");
1129 boolean cc = jargs.optBoolean("cc");
1130
1131 boolean isReply = TextUtils.isEmpty(to);
1132
1133 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
1134 boolean separate_reply = prefs.getBoolean("separate_reply", false);
1135 boolean extended_reply = prefs.getBoolean("extended_reply", false);
1136 boolean quote_reply = prefs.getBoolean("quote_reply", true);
1137 boolean quote = (quote_reply && isReply);
1138
1139 EntityIdentity identity = db.identity().getIdentity(iid);
1140 if (identity == null)
1141 throw new IllegalArgumentException("Rule identity not found name=" + rule.name);
1142
1143 EntityAnswer answer;
1144 if (aid < 0 || resend) {
1145 if (isReply)
1146 throw new IllegalArgumentException("Rule template missing name=" + rule.name);
1147
1148 answer = new EntityAnswer();
1149 answer.name = message.subject;
1150 answer.text = "";
1151 } else {
1152 answer = db.answer().getAnswer(aid);
1153 if (answer == null)
1154 throw new IllegalArgumentException("Rule template not found name=" + rule.name);
1155 }
1156
1157 EntityFolder outbox = EntityFolder.getOutbox(context);
1158
1159 Address[] from = new InternetAddress[]{new InternetAddress(identity.email, identity.name, StandardCharsets.UTF_8.name())};
1160
1161 // Prevent loop
1162 if (isReply) {
1163 List<EntityMessage> messages = db.message().getMessagesByThread(
1164 message.account, message.thread, null, null);
1165 for (EntityMessage threaded : messages)
1166 if (!threaded.id.equals(message.id) &&
1167 MessageHelper.equal(threaded.from, from)) {
1168 EntityLog.log(context, EntityLog.Type.Rules, message,
1169 "Answer loop" +
1170 " name=" + answer.name +
1171 " from=" + MessageHelper.formatAddresses(from));
1172 return;
1173 }

Callers 1

runMethod · 0.95

Calls 15

iMethod · 0.95
getInstanceMethod · 0.95
identityMethod · 0.95
answerMethod · 0.95
getOutboxMethod · 0.95
messageMethod · 0.95
equalMethod · 0.95
logMethod · 0.95
formatAddressesMethod · 0.95
generateMessageIdMethod · 0.95
parseAddressesMethod · 0.95
getSubjectMethod · 0.95

Tested by

no test coverage detected