From d691bd56f13c22dd9c56ea79fe7c967afd8fda8a Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 7 Jan 2020 16:47:08 +0100 Subject: [PATCH] Always reply to organizer of event --- .../eu/faircode/email/FragmentCompose.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index fd935470c7..c44075c4bc 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -169,6 +169,11 @@ import javax.mail.internet.MimeMultipart; import javax.mail.internet.ParseException; import javax.mail.util.ByteArrayDataSource; +import biweekly.Biweekly; +import biweekly.ICalendar; +import biweekly.component.VEvent; +import biweekly.property.Organizer; + import static android.app.Activity.RESULT_CANCELED; import static android.app.Activity.RESULT_OK; import static android.widget.AdapterView.INVALID_POSITION; @@ -3005,7 +3010,21 @@ public class FragmentCompose extends FragmentBase { attachment.progress = null; attachment.available = true; attachment.id = db.attachment().insertAttachment(attachment); - ics.renameTo(attachment.getFile(context)); + File file = attachment.getFile(context); + ics.renameTo(file); + + ICalendar icalendar = Biweekly.parse(file).first(); + VEvent event = icalendar.getEvents().get(0); + Organizer organizer = event.getOrganizer(); + if (organizer != null) { + String email = organizer.getEmail(); + String name = organizer.getCommonName(); + if (!TextUtils.isEmpty(email)) { + InternetAddress o = new InternetAddress(email, name); + Log.i("Setting organizer=" + o); + data.draft.to = new Address[]{o}; + } + } } if ("new".equals(action)) {