mirror of https://github.com/M66B/FairEmail.git
Replace answer tags in composer
This commit is contained in:
parent
a1d49dba54
commit
33b3049000
|
@ -66,33 +66,28 @@ public class EntityAnswer implements Serializable {
|
||||||
static String getAnswerText(EntityAnswer answer, Address[] from) {
|
static String getAnswerText(EntityAnswer answer, Address[] from) {
|
||||||
String name = null;
|
String name = null;
|
||||||
String email = null;
|
String email = null;
|
||||||
String first = null;
|
|
||||||
String last = null;
|
|
||||||
if (from != null && from.length > 0) {
|
if (from != null && from.length > 0) {
|
||||||
name = ((InternetAddress) from[0]).getPersonal();
|
name = ((InternetAddress) from[0]).getPersonal();
|
||||||
email = ((InternetAddress) from[0]).getAddress();
|
email = ((InternetAddress) from[0]).getAddress();
|
||||||
}
|
}
|
||||||
if (name != null) {
|
|
||||||
name = name.trim();
|
return replacePlaceholders(answer.text, name, email);
|
||||||
int c = name.lastIndexOf(",");
|
}
|
||||||
if (c < 0) {
|
|
||||||
c = name.lastIndexOf(" ");
|
static String replacePlaceholders(String text, String fullName, String email) {
|
||||||
if (c < 0) {
|
String firstName = null;
|
||||||
first = name;
|
String lastName = null;
|
||||||
last = name;
|
if (fullName != null) {
|
||||||
} else {
|
fullName = fullName.trim();
|
||||||
first = name.substring(0, c).trim();
|
int c = fullName.lastIndexOf(",");
|
||||||
last = name.substring(c + 1).trim();
|
if (c < 0)
|
||||||
}
|
c = fullName.lastIndexOf(" ");
|
||||||
} else {
|
if (c > 0) {
|
||||||
|
firstName = fullName.substring(0, c).trim();
|
||||||
|
lastName = fullName.substring(c + 1).trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return replacePlaceholders(answer.text, name, first, last, email);
|
|
||||||
}
|
|
||||||
|
|
||||||
static String replacePlaceholders(
|
|
||||||
String text, String fullName, String firstName, String lastName, String email) {
|
|
||||||
text = text.replace("$name$", fullName == null ? "" : fullName);
|
text = text.replace("$name$", fullName == null ? "" : fullName);
|
||||||
text = text.replace("$firstname$", firstName == null ? "" : firstName);
|
text = text.replace("$firstname$", firstName == null ? "" : firstName);
|
||||||
text = text.replace("$lastname$", lastName == null ? "" : lastName);
|
text = text.replace("$lastname$", lastName == null ? "" : lastName);
|
||||||
|
|
|
@ -1839,7 +1839,13 @@ public class FragmentCompose extends FragmentBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onAnswerSelected(Bundle args) {
|
private void onAnswerSelected(Bundle args) {
|
||||||
String text = args.getString("answer");
|
String answer = args.getString("answer");
|
||||||
|
|
||||||
|
EntityIdentity identity = (EntityIdentity) spIdentity.getSelectedItem();
|
||||||
|
String name = (identity == null ? null : identity.name);
|
||||||
|
String email = (identity == null ? null : identity.email);
|
||||||
|
String text = EntityAnswer.replacePlaceholders(answer, name, email);
|
||||||
|
|
||||||
Spanned spanned = HtmlHelper.fromHtml(text);
|
Spanned spanned = HtmlHelper.fromHtml(text);
|
||||||
etBody.getText().insert(etBody.getSelectionStart(), spanned);
|
etBody.getText().insert(etBody.getSelectionStart(), spanned);
|
||||||
}
|
}
|
||||||
|
@ -3548,10 +3554,7 @@ public class FragmentCompose extends FragmentBase {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
EntityAnswer answer = adapter.getItem(which);
|
EntityAnswer answer = adapter.getItem(which);
|
||||||
String text = EntityAnswer.replacePlaceholders(
|
getArguments().putString("answer", answer.text);
|
||||||
answer.text, null, null, null, null);
|
|
||||||
|
|
||||||
getArguments().putString("answer", text);
|
|
||||||
|
|
||||||
sendResult(RESULT_OK);
|
sendResult(RESULT_OK);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue