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

Method onActionUrl

app/src/main/java/eu/faircode/email/EntityRule.java:1563–1629  ·  view source on GitHub ↗
(Context context, EntityMessage message, JSONObject jargs, String html)

Source from the content-addressed store, hash-verified

1561 }
1562
1563 private boolean onActionUrl(Context context, EntityMessage message, JSONObject jargs, String html) throws JSONException, IOException {
1564 String url = jargs.getString("url");
1565 String method = jargs.optString("method");
1566 String body = (jargs.isNull("body") ? null : jargs.optString("body"));
1567
1568 if (TextUtils.isEmpty(method))
1569 method = "GET";
1570
1571 InternetAddress iaddr =
1572 (message.from == null || message.from.length == 0
1573 ? null : ((InternetAddress) message.from[0]));
1574 String address = (iaddr == null ? null : iaddr.getAddress());
1575 String personal = (iaddr == null ? null : iaddr.getPersonal());
1576
1577 // ISO 8601
1578 DateFormat DTF = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
1579 DTF.setTimeZone(java.util.TimeZone.getTimeZone("Zulu"));
1580
1581 url = url.replace("$" + EXTRA_RULE + "$", Uri.encode(name == null ? "" : name));
1582 url = url.replace("$" + EXTRA_SENDER + "$", Uri.encode(address == null ? "" : address));
1583 url = url.replace("$" + EXTRA_NAME + "$", Uri.encode(personal == null ? "" : personal));
1584 url = url.replace("$" + EXTRA_SUBJECT + "$", Uri.encode(message.subject == null ? "" : message.subject));
1585 url = url.replace("$" + EXTRA_RECEIVED + "$", Uri.encode(DTF.format(message.received)));
1586
1587 if (!TextUtils.isEmpty(body)) {
1588 body = body.replace("$" + EXTRA_RULE + "$", name == null ? "" : name);
1589 body = body.replace("$" + EXTRA_SENDER + "$", address == null ? "" : address);
1590 body = body.replace("$" + EXTRA_NAME + "$", personal == null ? "" : personal);
1591 body = body.replace("$" + EXTRA_SUBJECT + "$", message.subject == null ? "" : message.subject);
1592 body = body.replace("$" + EXTRA_RECEIVED + "$", DTF.format(message.received));
1593 }
1594
1595 Log.i("GET " + url);
1596
1597 HttpsURLConnection connection = null;
1598 try {
1599 connection = (HttpsURLConnection) new URL(url).openConnection();
1600 connection.setRequestMethod(method);
1601 connection.setDoOutput(body != null);
1602 connection.setReadTimeout(URL_TIMEOUT);
1603 connection.setConnectTimeout(URL_TIMEOUT);
1604 connection.setInstanceFollowRedirects(true);
1605 ConnectionHelper.setUserAgent(context, connection);
1606 connection.connect();
1607
1608 if (body != null)
1609 connection.getOutputStream().write(body.getBytes());
1610
1611 int status = connection.getResponseCode();
1612 if (status < 200 || status > 299) {
1613 String error = "Error " + status + ": " + connection.getResponseMessage();
1614 try {
1615 InputStream is = connection.getErrorStream();
1616 if (is != null)
1617 error += "\n" + Helper.readStream(is);
1618 } catch (Throwable ex) {
1619 Log.w(ex);
1620 }

Callers 1

_executeMethod · 0.95

Calls 15

getAddressMethod · 0.95
getPersonalMethod · 0.95
iMethod · 0.95
setUserAgentMethod · 0.95
readStreamMethod · 0.95
wMethod · 0.95
isNullMethod · 0.80
getOutputStreamMethod · 0.65
getStringMethod · 0.45
isEmptyMethod · 0.45
replaceMethod · 0.45
encodeMethod · 0.45

Tested by

no test coverage detected