1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2025-03-04 10:39:25 +00:00

Added body parameter to URL rule

This commit is contained in:
M66B 2025-01-11 09:07:39 +01:00
parent c4da7ae14f
commit 44b0a3367a
3 changed files with 47 additions and 7 deletions

View file

@ -1514,6 +1514,7 @@ public class EntityRule {
private boolean onActionUrl(Context context, EntityMessage message, JSONObject jargs, String html) throws JSONException, IOException {
String url = jargs.getString("url");
String method = jargs.optString("method");
String body = (jargs.isNull("body") ? null : jargs.optString("body"));
if (TextUtils.isEmpty(method))
method = "GET";
@ -1534,11 +1535,12 @@ public class EntityRule {
url = url.replace("$" + EXTRA_SUBJECT + "$", Uri.encode(message.subject == null ? "" : message.subject));
url = url.replace("$" + EXTRA_RECEIVED + "$", Uri.encode(DTF.format(message.received)));
String body = null;
if ("POST".equals(method) || "PUT".equals(method)) {
Uri u = Uri.parse(url);
body = u.getQuery();
url = u.buildUpon().clearQuery().build().toString();
if (!TextUtils.isEmpty(body)) {
body = body.replace("$" + EXTRA_RULE + "$", name == null ? "" : name);
body = body.replace("$" + EXTRA_SENDER + "$", address == null ? "" : address);
body = body.replace("$" + EXTRA_NAME + "$", personal == null ? "" : personal);
body = body.replace("$" + EXTRA_SUBJECT + "$", message.subject == null ? "" : message.subject);
body = body.replace("$" + EXTRA_RECEIVED + "$", DTF.format(message.received));
}
Log.i("GET " + url);

View file

@ -184,6 +184,7 @@ public class FragmentRule extends FragmentBase {
private Spinner spUrlMethod;
private EditText etUrl;
private EditText etContent;
private TextView tvUrlHint;
private BottomNavigationView bottom_navigation;
@ -392,6 +393,7 @@ public class FragmentRule extends FragmentBase {
spUrlMethod = view.findViewById(R.id.spUrlMethod);
etUrl = view.findViewById(R.id.etUrl);
etContent = view.findViewById(R.id.etContent);
tvUrlHint = view.findViewById(R.id.tvUrlHint);
bottom_navigation = view.findViewById(R.id.bottom_navigation);
@ -896,6 +898,27 @@ public class FragmentRule extends FragmentBase {
}
});
etContent.setEnabled(false);
spUrlMethod.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String method = null;
try {
String[] methods = getResources().getStringArray(R.array.httpMethodNames);
if (position >= 0 && position < methods.length)
method = methods[position];
} catch (Throwable ex) {
Log.e(ex);
}
etContent.setEnabled("POST".equals(method) || "PUT".equals(method));
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
etContent.setEnabled(false);
}
});
List<String> extras = new ArrayList<>();
for (String extra : EntityRule.EXTRA_ALL)
extras.add("$" + extra + "$");
@ -1475,6 +1498,7 @@ public class FragmentRule extends FragmentBase {
case EntityRule.TYPE_URL:
etUrl.setText(jaction.getString("url"));
etContent.setText(jaction.getString("body"));
String method = jaction.optString("method");
if (TextUtils.isEmpty(method))
method = "GET";
@ -1911,6 +1935,7 @@ public class FragmentRule extends FragmentBase {
case EntityRule.TYPE_URL:
jaction.put("url", etUrl.getText().toString().trim());
jaction.put("body", etContent.getText().toString());
int pos = spUrlMethod.getSelectedItemPosition();
String[] methods = getResources().getStringArray(R.array.httpMethodNames);
if (pos >= 0 && pos < methods.length)

View file

@ -1449,12 +1449,25 @@
android:id="@+id/etUrl"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="https://..."
android:inputType="textUri"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/spUrlMethod" />
<eu.faircode.email.EditTextPlain
android:id="@+id/etContent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:hint="{'example': true}"
android:inputType="text"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etUrl" />
<TextView
android:id="@+id/tvUrlHint"
android:layout_width="wrap_content"
@ -1464,7 +1477,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="italic"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/etUrl" />
app:layout_constraintTop_toBottomOf="@+id/etContent" />
<TextView
android:id="@+id/tvSummarizeRemark"
@ -1587,7 +1600,7 @@
android:id="@+id/grpUrl"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="tvUrl,spUrlMethod,etUrl,tvUrlHint" />
app:constraint_referenced_ids="tvUrl,spUrlMethod,etUrl,etContent,tvUrlHint" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpSummarize"