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) {
|
||||
String name = null;
|
||||
String email = null;
|
||||
String first = null;
|
||||
String last = null;
|
||||
if (from != null && from.length > 0) {
|
||||
name = ((InternetAddress) from[0]).getPersonal();
|
||||
email = ((InternetAddress) from[0]).getAddress();
|
||||
}
|
||||
if (name != null) {
|
||||
name = name.trim();
|
||||
int c = name.lastIndexOf(",");
|
||||
if (c < 0) {
|
||||
c = name.lastIndexOf(" ");
|
||||
if (c < 0) {
|
||||
first = name;
|
||||
last = name;
|
||||
} else {
|
||||
first = name.substring(0, c).trim();
|
||||
last = name.substring(c + 1).trim();
|
||||
}
|
||||
} else {
|
||||
|
||||
return replacePlaceholders(answer.text, name, email);
|
||||
}
|
||||
|
||||
static String replacePlaceholders(String text, String fullName, String email) {
|
||||
String firstName = null;
|
||||
String lastName = null;
|
||||
if (fullName != null) {
|
||||
fullName = fullName.trim();
|
||||
int c = fullName.lastIndexOf(",");
|
||||
if (c < 0)
|
||||
c = fullName.lastIndexOf(" ");
|
||||
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("$firstname$", firstName == null ? "" : firstName);
|
||||
text = text.replace("$lastname$", lastName == null ? "" : lastName);
|
||||
|
|
|
@ -1839,7 +1839,13 @@ public class FragmentCompose extends FragmentBase {
|
|||
}
|
||||
|
||||
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);
|
||||
etBody.getText().insert(etBody.getSelectionStart(), spanned);
|
||||
}
|
||||
|
@ -3548,10 +3554,7 @@ public class FragmentCompose extends FragmentBase {
|
|||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
EntityAnswer answer = adapter.getItem(which);
|
||||
String text = EntityAnswer.replacePlaceholders(
|
||||
answer.text, null, null, null, null);
|
||||
|
||||
getArguments().putString("answer", text);
|
||||
getArguments().putString("answer", answer.text);
|
||||
|
||||
sendResult(RESULT_OK);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue