This commit is contained in:
2020-06-15 23:02:09 +00:00
parent 9539628199
commit 1dc4ab7f59
2 changed files with 51 additions and 19 deletions

View File

@@ -86,8 +86,3 @@ route:
API API
Add email verification route with code (called by RAVEN) Add email verification route with code (called by RAVEN)
emails us when it's verified as a notification that a trial is ready to send emails us when it's verified as a notification that a trial is ready to send

View File

@@ -14,6 +14,14 @@ using MimeKit.Utils;
namespace rockfishCore.Util namespace rockfishCore.Util
{ {
/*
HOW TO DIAGNOSE ISSUES:
Get a protocol log:
https://github.com/jstedfast/MailKit/blob/master/FAQ.md#ProtocolLog
docs http://www.mimekit.net/docs/html/Introduction.htm
*/
//http://www.mimekit.net/ //http://www.mimekit.net/
public static class RfMail public static class RfMail
{ {
@@ -603,14 +611,13 @@ namespace rockfishCore.Util
{ {
//Console.WriteLine($"getInboxSummariesFor {sourceAccount}"); //Console.WriteLine($"getInboxSummariesFor {sourceAccount}");
List<rfMessageSummary> ret = new List<rfMessageSummary>(); List<rfMessageSummary> ret = new List<rfMessageSummary>();
using (var client = new ImapClient()) using (var client = new ImapClient())
// using (var client = new ImapClient(new ProtocolLogger(Console.OpenStandardOutput())))
{ {
// Accept all SSL certificates // Accept all SSL certificates
client.ServerCertificateValidationCallback = (s, c, h, e) => true; client.ServerCertificateValidationCallback = (s, c, h, e) => true;
//client.Connect(MAIL_IMAP_ADDRESS, MAIL_IMAP_PORT, true);
//testing
//Console.WriteLine($"connecting to {MAIL_IMAP_ADDRESS} on {MAIL_IMAP_PORT}"); //Console.WriteLine($"connecting to {MAIL_IMAP_ADDRESS} on {MAIL_IMAP_PORT}");
client.Connect(MAIL_IMAP_ADDRESS, MAIL_IMAP_PORT); client.Connect(MAIL_IMAP_ADDRESS, MAIL_IMAP_PORT);
@@ -625,28 +632,58 @@ namespace rockfishCore.Util
var inbox = client.Inbox; var inbox = client.Inbox;
//Console.WriteLine($"opening inbox..."); //Console.WriteLine($"opening inbox...");
inbox.Open(FolderAccess.ReadOnly); inbox.Open(FolderAccess.ReadOnly);
//Console.WriteLine($"fetching summaries...");
var summaries = inbox.Fetch(0, -1, MessageSummaryItems.Full | MessageSummaryItems.UniqueId);
//Console.WriteLine($"disconnecting..."); for (int i = 0; i < inbox.Count; i++)
client.Disconnect(true);
foreach (var summary in summaries)
{ {
var message = inbox.GetMessage(i);
//Sometimes bad hombres don't set a from address so don't expect one //Sometimes bad hombres don't set a from address so don't expect one
string sFrom = "UNKNOWN / NOT SET"; string sFrom = "UNKNOWN / NOT SET";
if (summary.Envelope.From.Count > 0) if (message.From.Count > 0)
{ {
sFrom = summary.Envelope.From[0].ToString().Replace("\"", "").Replace("<", "").Replace(">", "").Trim(); sFrom = message.From[0].ToString().Replace("\"", "").Replace("<", "").Replace(">", "").Trim();
} }
//get flags
var summ = inbox.Fetch(new[] { i }, MessageSummaryItems.Flags | MessageSummaryItems.UniqueId);
ret.Add(new rfMessageSummary ret.Add(new rfMessageSummary
{ {
account = sourceAccount, account = sourceAccount,
id = summary.UniqueId.Id, id = summ[0].UniqueId.Id,
subject = summary.Envelope.Subject, subject = message.Subject,
sent = DateUtil.DateTimeOffSetNullableToEpoch(summary.Envelope.Date), sent = DateUtil.DateTimeOffSetNullableToEpoch(message.Date),
from = sFrom, from = sFrom,
flags = summary.Flags.ToString().ToLowerInvariant() flags = summ[0].Flags.ToString().ToLowerInvariant()
}); });
Console.WriteLine("Subject: {0}", message.Subject);
} }
//This was failing with an exception
//re-wrote from an example on the mailkit page and it works fine
//so going with the new method now
// //Console.WriteLine($"fetching summaries...");
// var summaries = inbox.Fetch(0, -1, MessageSummaryItems.Full | MessageSummaryItems.UniqueId);
// //Console.WriteLine($"disconnecting...");
// client.Disconnect(true);
// foreach (var summary in summaries)
// {
// //Sometimes bad hombres don't set a from address so don't expect one
// string sFrom = "UNKNOWN / NOT SET";
// if (summary.Envelope.From.Count > 0)
// {
// sFrom = summary.Envelope.From[0].ToString().Replace("\"", "").Replace("<", "").Replace(">", "").Trim();
// }
// ret.Add(new rfMessageSummary
// {
// account = sourceAccount,
// id = summary.UniqueId.Id,
// subject = summary.Envelope.Subject,
// sent = DateUtil.DateTimeOffSetNullableToEpoch(summary.Envelope.Date),
// from = sFrom,
// flags = summary.Flags.ToString().ToLowerInvariant()
// });
// }
} }
//reverse the results array as emails come in oldest first order but we want oldest last //reverse the results array as emails come in oldest first order but we want oldest last
ret.Reverse(); ret.Reverse();