(Context context, EntityRule rule, EntityMessage message, JSONObject jargs)
| 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 | } |
no test coverage detected