Check-in [94dd79783d]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:More logical population of message-related things.
Timelines: family | ancestors | descendants | both | dotnet
Files: files | file ages | folders
SHA1: 94dd79783dcb99d4c623c969b4d12b570192b90a
User & Date: tinus 2019-09-13 18:56:24
Wiki:dotnet
Context
2019-09-13
20:46
Check for errors in Uglify output. check-in: 87b1f645a6 user: tinus tags: dotnet
18:58
Merge dotnet into dotnet/timers. check-in: e57149797c user: tinus tags: dotnet/timers
18:56
More logical population of message-related things. check-in: 94dd79783d user: tinus tags: dotnet
18:54
Move retrieval of existing messageIDs to FolderMessages repository. check-in: b5185ef288 user: tinus tags: dotnet
Changes

Changes to MailSynchronizer.cs.

316
317
318
319
320
321
322
323






324
325
326
327
328
329
330
...
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
...
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
                            await work.FolderMessages.AddAsync(folderMessage);
                        }
                        dbMessage = folderMessage.Message;
                        dbMessage.GlobalID = summary.GMailMessageId;
                        dbMessage.DateRetrievedUTC = DateTime.UtcNow;
                        dbMessage.Flags = summary.Flags ?? MessageFlags.None;
                        dbMessage.DateReceived = summary.InternalDate;
                        await PopulateMessageAsync(work, dbMessage, mailMessage, summary.Keywords, summary.GMailLabels);






                    }
                    await work.SaveChangesAsync();
                }
                catch (Exception ex)
                {
                    if (ex is TaskCanceledException || ex is OperationCanceledException || ex is ServiceNotConnectedException)
                    {
................................................................................
                if (vacuumDatabase && (_haveDeleted || numDeleted > 0))
                {
                    await work.DB.Database.ExecuteSqlCommandAsync("VACUUM", _cancellationToken);
                }
            }
        }

        private async Task PopulateMessageAsync(UnitOfWork work, Message targetMsg, MimeMessage sourceMsg,
                                                IEnumerable<string> keywords, IEnumerable<string> labels)
        {
            targetMsg.RfcMessageID = sourceMsg.ResentMessageId ?? sourceMsg.MessageId; // TODO: reverse these?
            targetMsg.Subject = sourceMsg.Subject;
            targetMsg.Date = sourceMsg.Date;
            targetMsg.From = new InternetAddressList(sourceMsg.From.Concat(sourceMsg.ResentFrom)).ToString();
            targetMsg.To = new InternetAddressList(sourceMsg.To.Concat(sourceMsg.ResentTo)).ToString();
            targetMsg.Cc = new InternetAddressList(sourceMsg.Cc.Concat(sourceMsg.ResentCc)).ToString();
................................................................................
                    }
                    using (var compressedStream = entry.Open())
                        await sourceMsg.WriteToAsync(compressedStream);
                }
                targetMsg.Original = zipStream.ToArray();
            }
            // TODO: skip the above if we only have the headers

            // Store all separate entities contained in the mail message
            await PopulateParticipantsAsync(work, targetMsg, sourceMsg);    // from headers
            await PopulateKeywordsAsync(work, targetMsg, keywords, labels); // from summary
            await PopulateReferencesAsync(work, targetMsg, sourceMsg);      // from summary + headers
        } // PopulateMessageAsync

        private static string CreateMessageFilename(MimeMessage sourceMsg, string extension = ".eml")
        {
            string subject = MakeSafe(sourceMsg.Subject);
            InternetAddress sender = sourceMsg.From.FirstOrDefault();
            string senderName = MakeSafe(sender?.Name ?? sender?.ToString());







|
>
>
>
>
>
>







 







|
<







 







<
<
<
<
<







316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
...
413
414
415
416
417
418
419
420

421
422
423
424
425
426
427
...
457
458
459
460
461
462
463





464
465
466
467
468
469
470
                            await work.FolderMessages.AddAsync(folderMessage);
                        }
                        dbMessage = folderMessage.Message;
                        dbMessage.GlobalID = summary.GMailMessageId;
                        dbMessage.DateRetrievedUTC = DateTime.UtcNow;
                        dbMessage.Flags = summary.Flags ?? MessageFlags.None;
                        dbMessage.DateReceived = summary.InternalDate;
                        await PopulateMessageAsync(dbMessage, mailMessage, summary.Keywords);

                        // Store all separate entities contained in the mail message
                        await PopulateParticipantsAsync(work, dbMessage, mailMessage);    // from headers
                        await PopulateKeywordsAsync(work, dbMessage, summary.Keywords, summary.GMailLabels); // from summary
                        await PopulateReferencesAsync(work, dbMessage, mailMessage);      // from summary + headers

                    }
                    await work.SaveChangesAsync();
                }
                catch (Exception ex)
                {
                    if (ex is TaskCanceledException || ex is OperationCanceledException || ex is ServiceNotConnectedException)
                    {
................................................................................
                if (vacuumDatabase && (_haveDeleted || numDeleted > 0))
                {
                    await work.DB.Database.ExecuteSqlCommandAsync("VACUUM", _cancellationToken);
                }
            }
        }

        private async Task PopulateMessageAsync(Message targetMsg, MimeMessage sourceMsg, IEnumerable<string> keywords)

        {
            targetMsg.RfcMessageID = sourceMsg.ResentMessageId ?? sourceMsg.MessageId; // TODO: reverse these?
            targetMsg.Subject = sourceMsg.Subject;
            targetMsg.Date = sourceMsg.Date;
            targetMsg.From = new InternetAddressList(sourceMsg.From.Concat(sourceMsg.ResentFrom)).ToString();
            targetMsg.To = new InternetAddressList(sourceMsg.To.Concat(sourceMsg.ResentTo)).ToString();
            targetMsg.Cc = new InternetAddressList(sourceMsg.Cc.Concat(sourceMsg.ResentCc)).ToString();
................................................................................
                    }
                    using (var compressedStream = entry.Open())
                        await sourceMsg.WriteToAsync(compressedStream);
                }
                targetMsg.Original = zipStream.ToArray();
            }
            // TODO: skip the above if we only have the headers





        } // PopulateMessageAsync

        private static string CreateMessageFilename(MimeMessage sourceMsg, string extension = ".eml")
        {
            string subject = MakeSafe(sourceMsg.Subject);
            InternetAddress sender = sourceMsg.From.FirstOrDefault();
            string senderName = MakeSafe(sender?.Name ?? sender?.ToString());