Check-in [4b554307bf]

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

Overview
Comment:Added documentation comments.
Timelines: family | ancestors | descendants | both | dotnet
Files: files | file ages | folders
SHA1: 4b554307bf9152ed300c7cf83a22d62a3988c8c0
User & Date: tinus 2019-09-14 06:47:58
Wiki:dotnet
Context
2019-09-25
21:51
Upgraded to .NET Core 3.0. Set project to use non-nullable reference types by default. check-in: 9eecbcebf2 user: tinus tags: dotnet/nullable
2019-09-14
06:47
Added documentation comments. Leaf check-in: 4b554307bf user: tinus tags: dotnet
06:22
Updated initial migration to accomodate MessageParticipant.Name. check-in: 0cfda9d5ec user: tinus tags: dotnet
Changes

Changes to MailJanitorContext.cs.

1
2
3
4
5
6

7
8
9
10
11
12
13
..
29
30
31
32
33
34
35






36
37
38
39
40
41
42
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MailJanitor.Models;
using Microsoft.EntityFrameworkCore;


namespace MailJanitor
{
    public class MailJanitorContext : DbContext
    {
        public DbSet<Account> Accounts { get; set; }
        public DbSet<Folder> Folders { get; set; }
................................................................................
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.Entity<Message>(b =>
            {
                b.HasIndex(m => m.GlobalID);
                b.HasIndex(m => m.RfcMessageID);






            });

            modelBuilder.Entity<Participant>(b =>
            {
                b.HasIndex(p => new { p.Address, p.Name })
                    .IsUnique();
            });






>







 







>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
..
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MailJanitor.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

namespace MailJanitor
{
    public class MailJanitorContext : DbContext
    {
        public DbSet<Account> Accounts { get; set; }
        public DbSet<Folder> Folders { get; set; }
................................................................................
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.Entity<Message>(b =>
            {
                b.HasIndex(m => m.GlobalID);
                b.HasIndex(m => m.RfcMessageID);
                //b.Property(m => m.Date)
                //    .HasConversion(new DateTimeOffsetToBinaryConverter());
                //b.Property(m => m.DateReceived)
                //    .HasConversion(new DateTimeOffsetToBinaryConverter());
                //b.Property(m => m.DateRetrievedUTC)
                //    .HasConversion(new DateTimeToBinaryConverter());
            });

            modelBuilder.Entity<Participant>(b =>
            {
                b.HasIndex(p => new { p.Address, p.Name })
                    .IsUnique();
            });

Changes to Program.cs.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
..
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
..
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using CommandLine;
using MailKit;
using MC.Utilities;
using Microsoft.EntityFrameworkCore;

namespace MailJanitor
{
    class Program
    {
        public enum ResultCode
        {
................................................................................
                                                           new NetworkCredential(o.EmailAddress, o.Password),
                                                           FetchFolder,
                                                           o.VacuumDatabase).Wait();
                            bool FetchFolder(IMailFolder mailFolder)
                            {
                                var offendingAttributes = FolderAttributes.Drafts
                                                        | FolderAttributes.All
                                                        | FolderAttributes.Archive 
                                                        | FolderAttributes.Trash 
                                                        | FolderAttributes.Junk;
                                return (mailFolder.Attributes & offendingAttributes) == FolderAttributes.None;
                            }
                        }
                        result = ResultCode.Ok;
                    })
                    .WithNotParsed(error =>
................................................................................
                    {
                        result = ResultCode.WrongArgument;
                    });
            }
            catch (Exception ex)
            {
                Con.WriteLine(ex);
                // #if DEBUG
                //                 if (!Console.IsErrorRedirected)
                //                 {
                //                     Console.WriteLine("Press a key to end...");
                //                     Console.ReadKey();
                //                 }
                // #endif

                // Return meaningful error codes
                if (ex is TaskCanceledException || ex is OperationCanceledException) result = ResultCode.Cancelled; // operation canceled
                else if (ex is ServiceNotAuthenticatedException) result = ResultCode.AuthenticationProblem; // authentication problem
                else if (ex is ServiceNotConnectedException) result = ResultCode.ConnectionProblem; // mail server connection problem
                else result = ResultCode.Exception; // unexpected problem
            }
            return (int)result;
        }

        // TODO: use an FTS table to enable searching for messages
    }
}







<







 







|
|







 







|
|
|
|
|
|
|
|
|
|
<
<
<







1
2
3
4
5
6
7

8
9
10
11
12
13
14
..
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
..
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75



76
77
78
79
80
81
82
using System;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using CommandLine;
using MailKit;
using MC.Utilities;


namespace MailJanitor
{
    class Program
    {
        public enum ResultCode
        {
................................................................................
                                                           new NetworkCredential(o.EmailAddress, o.Password),
                                                           FetchFolder,
                                                           o.VacuumDatabase).Wait();
                            bool FetchFolder(IMailFolder mailFolder)
                            {
                                var offendingAttributes = FolderAttributes.Drafts
                                                        | FolderAttributes.All
                                                        | FolderAttributes.Archive
                                                        | FolderAttributes.Trash
                                                        | FolderAttributes.Junk;
                                return (mailFolder.Attributes & offendingAttributes) == FolderAttributes.None;
                            }
                        }
                        result = ResultCode.Ok;
                    })
                    .WithNotParsed(error =>
................................................................................
                    {
                        result = ResultCode.WrongArgument;
                    });
            }
            catch (Exception ex)
            {
                Con.WriteLine(ex);

                // Return meaningful error codes
                if (ex is TaskCanceledException || ex is OperationCanceledException)
                    result = ResultCode.Cancelled;
                else if (ex is ServiceNotAuthenticatedException)
                    result = ResultCode.AuthenticationProblem;
                else if (ex is ServiceNotConnectedException)
                    result = ResultCode.ConnectionProblem;
                else
                    result = ResultCode.Exception;



            }
            return (int)result;
        }

        // TODO: use an FTS table to enable searching for messages
    }
}

Changes to Repositories/FolderMessagesRepository.cs.

9
10
11
12
13
14
15



16
17
18
19
20
21
22
23









24
25
26
27
28
29
30
{
    public class FolderMessagesRepository : Repository<FolderMessage>
    {
        public FolderMessagesRepository(MailJanitorContext db, CancellationToken cancellationToken = default(CancellationToken)) : base(db, cancellationToken)
        {
        }




        public Task<uint> GetMaxUIDAsync(Folder folder)
        {
            return _db.FolderMessages
                .Where(fm => fm.Folder == folder)
                .DefaultIfEmpty()
                .MaxAsync(fm => fm == null ? 0 : fm.UID, _cancellationToken);
        }










        public async Task<Dictionary<ulong, (long? folderMsgID, long? messageID)>> GetIDsByGlobalIDAsync(long dbFolderID, IEnumerable<ulong> globalIDs)
        {
            return await(from dbMessage in _db.Messages
                         where globalIDs.Contains(dbMessage.GlobalID.Value)
                         join folderMsg in _set.Where(folderMsg => folderMsg.FolderID == dbFolderID)
                              on dbMessage.ID equals folderMsg.MessageID
                              into folderMsgs







>
>
>








>
>
>
>
>
>
>
>
>







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
{
    public class FolderMessagesRepository : Repository<FolderMessage>
    {
        public FolderMessagesRepository(MailJanitorContext db, CancellationToken cancellationToken = default(CancellationToken)) : base(db, cancellationToken)
        {
        }

        /// <summary>
        /// Retrieves the highest UID in the given <paramref name="folder"/>.
        /// </summary>
        public Task<uint> GetMaxUIDAsync(Folder folder)
        {
            return _db.FolderMessages
                .Where(fm => fm.Folder == folder)
                .DefaultIfEmpty()
                .MaxAsync(fm => fm == null ? 0 : fm.UID, _cancellationToken);
        }

        /// <summary>
        /// Retrieves a list of <see cref="FolderMessage.ID"/>s and <see cref="Message.ID"/>s matching the given
        /// <paramref name="globalIDs"/> in the given <paramref name="dbFolderID"/>.
        /// </summary>
        /// <param name="dbFolderID">The ID of the folder containing those messages.</param>
        /// <param name="globalIDs">A list of server-wide IDs for the messages we're looking for.</param>
        /// <returns>A <see cref="Dictionary{ulong, (long? folderMsgID, long? messageID)}"/> containing, for each server-wide ID,
        /// a tuple with the corresponding <see cref="FolderMessage.ID"/> and <see cref="Message.ID"/>. These can be
        /// <see cref="null"/> if not present in the database.</returns>
        public async Task<Dictionary<ulong, (long? folderMsgID, long? messageID)>> GetIDsByGlobalIDAsync(long dbFolderID, IEnumerable<ulong> globalIDs)
        {
            return await(from dbMessage in _db.Messages
                         where globalIDs.Contains(dbMessage.GlobalID.Value)
                         join folderMsg in _set.Where(folderMsg => folderMsg.FolderID == dbFolderID)
                              on dbMessage.ID equals folderMsg.MessageID
                              into folderMsgs