Esempio n. 1
0
        public Result <MimeMessage> Process(MimeMessage originalEmail, IEnumerable <Tuple <string, byte[]> > attachments)
        {
            var excelAttachment = attachments.First(a => a.Item1.Contains("xlsx")).Item2;

            using (var stream = new MemoryStream(excelAttachment))
                using (var excelDoc = new ExcelPackage(stream))
                {
                    var settingsSheet = excelDoc.Workbook
                                        .Worksheets
                                        .FirstOrDefault(sheet => sheet.Name.StartsWith("settings", StringComparison.CurrentCultureIgnoreCase));

                    var customSheets = excelDoc.Workbook
                                       .Worksheets
                                       .Where(_settingsStore.IsCustomWorksheet)
                                       .ToList();

                    if (settingsSheet == null && customSheets.IsEmpty())
                    {
                        return(Result.Success(ConstructSettingsUpdateErrorMessage(originalEmail)));
                    }

                    var settingsUserId = originalEmail.From.Mailboxes.First().HashedEmail();
                    _settingsStore.UpdateSettings(settingsSheet, settingsUserId);
                    _settingsStore.UpdateCustomSheets(customSheets, settingsUserId);

                    return(Result.Success(MailUtility.ConstructReply(originalEmail, new MailboxAddress(_from), builder =>
                    {
                        builder.TextBody = @"I got your settings update! I'll take those into account next time around.

See you next time!";
                    })));
                }
        }
Esempio n. 2
0
        public Result <MimeMessage> Process(MimeMessage message, IEnumerable <Tuple <string, byte[]> > attachments)
        {
            return(Result.Success(MailUtility.ConstructReply(message, new MailboxAddress(_from), builder =>
            {
                builder.TextBody = $@"It looks like you might not know what you're doing.

Here's a link to some help: {MailUtility.HelpDocUrl}
";
            })));
        }
Esempio n. 3
0
        private MimeMessage ConstructSettingsUpdateErrorMessage(MimeMessage original)
        {
            return(MailUtility.ConstructReply(original, new MailboxAddress(_from), builder =>
            {
                builder.TextBody = $@"To update your settings, include the word 'settings' in your subject, and attach an Excel document.

The Excel document should have either the 'Settings' sheet from your latest report and/or custom sheets you'd like included in your next report. Custom sheets should start with the word 'custom'.

You can include the rest of the document too, I'll just ignore the rest of it.

For more information, take a look at the help, here: {MailUtility.HelpDocUrl}
";
            }));
        }
Esempio n. 4
0
        public Result <MimeMessage> Process(MimeMessage originalEmail, IEnumerable <Tuple <string, byte[]> > attachments)
        {
            var theExportZip   = GetExportZip(originalEmail, attachments);
            var attachment     = ExcelReport.CreateReport(theExportZip, _settings, _customSheets);
            var attachmentName = $"export.{originalEmail.Date.Date:yyyy-MM-dd}.xlsx";

            var reply = MailUtility.ConstructReply(originalEmail, new MailboxAddress(_from), builder =>
            {
                builder.TextBody = @"Hey there, I saw your health data... good work!";
                builder.Attachments.Add(attachmentName, attachment);
            });

            return(Result.Success(reply));
        }