Ejemplo n.º 1
0
        public void MailMonitor_StartMonitorTask_SeenUidsManager_Verify()
        {
            var mockMailProvider    = new Mock <IMailProvider>();
            var mockMailAction      = new Mock <IMailAction>();
            var mockSeenUidsManager = new Mock <ISeenUidsManager>();

            mockMailProvider
            .Setup(x => x.GetAllMessages(ConfigEntity))
            .Returns(MailTransfer);
            mockMailProvider
            .Setup(x => x.GetUnseenMessages(It.IsAny <ConfigEntity>(), It.IsAny <List <string> >()))
            .Returns(MailTransfer);
            mockSeenUidsManager
            .Setup(x => x.Write(It.IsAny <ConfigEntity>(), It.IsAny <List <string> >(), It.IsAny <bool>()))
            .Returns(true);
            mockSeenUidsManager
            .Setup(x => x.Read(It.IsAny <ConfigEntity>()))
            .Returns(It.IsAny <List <string> >());

            var mailMonitor = new MailMonitor(mockMailProvider.Object, mockMailAction.Object, mockSeenUidsManager.Object);

            mailMonitor.StartMonitorTask(ConfigEntity);

            mockSeenUidsManager.Verify();
        }
Ejemplo n.º 2
0
        public bool NotifyTo(MailEntity message)
        {
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("\nNotify ...");
            Console.ForegroundColor = ConsoleColor.Gray;

            var mailTo = MailMonitor.GetMailTo(message);

            Console.WriteLine();
            Console.WriteLine($"To:      {mailTo}");
            Console.WriteLine($"From:    {message.From}");
            Console.WriteLine($"Data:    {message.DateSent}");
            Console.WriteLine($"Subject: {message.Subject}");
            Console.WriteLine($"Body:    {message.Body}");

            return(true);
        }
Ejemplo n.º 3
0
        public bool CopyTo(ConfigEntity configEntity, MailEntity message, string mailActionValue)
        {
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine($"\nCopyToFolder: {mailActionValue}");
            Console.ForegroundColor = ConsoleColor.Gray;

            string        path    = AppDomain.CurrentDomain.BaseDirectory + @"Files";
            string        subpath = mailActionValue;
            DirectoryInfo dirInfo = new DirectoryInfo(path);

            if (!dirInfo.Exists)
            {
                dirInfo.Create();
            }

            if (string.IsNullOrEmpty(subpath))
            {
                subpath = "";
            }
            else
            {
                dirInfo.CreateSubdirectory(subpath);
            }

            string writePath = Path.Combine(path, subpath, configEntity.Mail + " " + message.DateSent.ToString("d") + ".txt");

            StringBuilder mailResult = new StringBuilder();

            mailResult.Append("To:      " + MailMonitor.GetMailTo(message));
            mailResult.AppendLine();
            mailResult.Append("From:    " + message.From);
            mailResult.AppendLine();
            mailResult.Append("Subject: " + message.Subject);
            mailResult.AppendLine();
            mailResult.Append("Body:    " + message.Body);

            using (StreamWriter sw = new StreamWriter(writePath, false, Encoding.Default))
            {
                sw.WriteLineAsync(mailResult.ToString());
            }

            Console.WriteLine("Письмо скопировано");
            return(true);
        }
Ejemplo n.º 4
0
        public void MailMonitor_StartMonitorTask_SeenUidsManager_Write_ExceptionThrown()
        {
            var mockMailProvider    = new Mock <IMailProvider>();
            var mockMailAction      = new Mock <IMailAction>();
            var mockSeenUidsManager = new Mock <ISeenUidsManager>();

            mockMailProvider
            .Setup(x => x.GetAllMessages(ConfigEntity))
            .Returns(MailTransfer);
            mockSeenUidsManager
            .Setup(x => x.Write(It.IsAny <ConfigEntity>(), It.IsAny <List <string> >(), It.IsAny <bool>()))
            .Returns(false);

            var mailMonitor = new MailMonitor(mockMailProvider.Object, mockMailAction.Object, mockSeenUidsManager.Object);

            string message = "Ошибка при сохранении Uid прочитанных писем";
            var    ex      = Assert.Throws <ApplicationException>(() => mailMonitor.StartMonitorTask(ConfigEntity));

            StringAssert.Contains(message, ex.Message);
        }
Ejemplo n.º 5
0
        public bool PrintTo(MailEntity message)
        {
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("\nPrint ...");
            Console.ForegroundColor = ConsoleColor.Gray;

            MailResult = new StringBuilder();
            MailResult.Append("To:      " + MailMonitor.GetMailTo(message));
            MailResult.AppendLine();
            MailResult.Append("From:    " + message.From);
            MailResult.AppendLine();
            MailResult.Append("Subject: " + message.Subject);
            MailResult.AppendLine();
            MailResult.Append("Body:    " + message.Body);

            PrintDocument printDoc = new PrintDocument();

            printDoc.PrintPage += PrintPageHandler;

            printDoc.Print();
            Console.WriteLine("Письмо распечатано");
            return(true);
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            var parsed = ArgumentParser.Parse(args);

            if (!parsed.ParsedOk)
            {
                return;
            }
            string action = args.Length != 0 ? args[0] : "";

            if (parsed.Arguments.ContainsKey("display"))
            {
                Console.WriteLine("[+] Setting to display e-mails");
                Common.display = true;
            }
            if (parsed.Arguments.ContainsKey("force"))
            {
                Console.WriteLine("[+] Enabling force");
                Common.force = true;
            }
            MailSearcher       ms = new MailSearcher(force: Common.force);
            AttachmentSearcher at = new AttachmentSearcher();

            switch (action.ToLower())
            {
            case "read":
                Common.display = true;
                if (parsed.Arguments.ContainsKey("number"))
                {
                    ms.ReadEmailByNumber(int.Parse(parsed.Arguments["number"]));
                }
                else if (parsed.Arguments.ContainsKey("subject"))
                {
                    ms.ReadEmailBySubject(parsed.Arguments["subject"]);
                }
                else if (parsed.Arguments.ContainsKey("entryid"))
                {
                    var item = ms.ReadEmailByID(parsed.Arguments["entryid"], OlDefaultFolders.olFolderInbox);
                    if (item is MailItem mailItem)
                    {
                        Common.DisplayMailItem(mailItem);
                    }
                    else if (item is MeetingItem meetingItem)
                    {
                        Common.DisplayMeetingItem(meetingItem);
                    }
                }
                else
                {
                    Common.PrintHelp();
                }
                break;

            case "searchmail":
                string searchMethod;
                try
                {
                    searchMethod = args[1].TrimStart('/');
                }
                catch
                {
                    searchMethod = "all";
                }
                switch (searchMethod.ToLower())
                {
                case "body":
                    if (parsed.Arguments.ContainsKey("regex"))
                    {
                        ms.SearchByContentRegex(parsed.Arguments["regex"]);
                    }
                    else if (parsed.Arguments.ContainsKey("content"))
                    {
                        string[] keywords = parsed.Arguments["content"].Split(',');
                        ms.SearchByContent(keywords);
                    }
                    break;

                case "senderaddress":
                    if (parsed.Arguments.ContainsKey("regex"))
                    {
                        ms.SearchByAddressRegex(parsed.Arguments["regex"]);
                    }
                    else if (parsed.Arguments.ContainsKey("address"))
                    {
                        ms.SearchByAddress(parsed.Arguments["address"]);
                    }
                    break;

                case "subject":
                    if (parsed.Arguments.ContainsKey("regex"))
                    {
                        ms.SearchBySubjectRegex(parsed.Arguments["regex"]);
                    }
                    else if (parsed.Arguments.ContainsKey("content"))
                    {
                        ms.SearchBySubject(parsed.Arguments["content"]);
                    }
                    break;

                case "attachment":
                    if (parsed.Arguments.ContainsKey("regex"))
                    {
                        if (parsed.Arguments.ContainsKey("download"))
                        {
                            if (parsed.Arguments.ContainsKey("downloadpath"))
                            {
                                at = new AttachmentSearcher(true, parsed.Arguments["downloadpath"]);
                                at.GetAttachmentsByRegex(parsed.Arguments["regex"]);
                            }
                            else
                            {
                                Console.WriteLine("Missing download path parameter!");
                                Common.PrintHelp();
                            }
                        }
                        else
                        {
                            at.GetAttachmentsByRegex(parsed.Arguments["regex"]);
                        }
                    }
                    else if (parsed.Arguments.ContainsKey("name"))
                    {
                        if (parsed.Arguments.ContainsKey("download"))
                        {
                            if (parsed.Arguments.ContainsKey("downloadpath"))
                            {
                                at = new AttachmentSearcher(true, parsed.Arguments["downloadpath"]);
                                at.GetAttachmentsByKeyword(parsed.Arguments["name"]);
                            }
                            else
                            {
                                Console.WriteLine("Missing download path parameter!");
                                Common.PrintHelp();
                            }
                        }
                        else
                        {
                            at.GetAttachmentsByKeyword(parsed.Arguments["name"]);
                        }
                    }
                    break;

                case "all":
                    ms.GetAll();
                    break;

                default:
                    ms.GetAll();
                    break;
                }
                break;

            case "monitor":
                MailMonitor mm = new MailMonitor();
                if (parsed.Arguments.ContainsKey("regex"))
                {
                    mm.Start(parsed.Arguments["regex"]);
                }
                else
                {
                    mm.Start();
                }
                while (true)
                {
                }
                break;

            case "send":
                if (parsed.Arguments.ContainsKey("recipients") && parsed.Arguments.ContainsKey("subject") && parsed.Arguments.ContainsKey("body"))
                {
                    MailSender sender = new MailSender();
                    if (parsed.Arguments.ContainsKey("attachment"))
                    {
                        string AttachmentName;
                        if (parsed.Arguments.ContainsKey("attachmentname"))
                        {
                            AttachmentName = parsed.Arguments["attachmentname"];
                        }
                        else
                        {
                            AttachmentName = Path.GetFileNameWithoutExtension(parsed.Arguments["attachment"]);
                        }
                        sender.SendEmail(parsed.Arguments["recipients"].Split(','), parsed.Arguments["body"], parsed.Arguments["subject"], parsed.Arguments["attachment"], AttachmentName);
                    }
                    else
                    {
                        sender.SendEmail(parsed.Arguments["recipients"].Split(','), parsed.Arguments["body"], parsed.Arguments["subject"]);
                    }
                }
                break;

            case "attachments":
                if (!parsed.Arguments.ContainsKey("downloadpath"))
                {
                    Console.WriteLine("Missing downloadpath parameter!");
                    Common.PrintHelp();
                    break;
                }
                at = new AttachmentSearcher(download: true, downloadFolder: parsed.Arguments["downloadpath"]);

                if (parsed.Arguments.ContainsKey("all"))
                {
                    at.GetAllAttachments();
                }
                else if (parsed.Arguments.ContainsKey("entryid"))
                {
                    at.GetAttachmentsByID(parsed.Arguments["entryid"], OlDefaultFolders.olFolderInbox);
                }
                break;

            default:
                Common.PrintHelp();
                break;
            }

            Console.WriteLine("Done.");
        }
Ejemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="service"></param>
        private static void RunSample(AuditService service)
        {
            //A sample base64 encoded PGP format key
            string sampleKey = "LS0tLS1CRUdJTiBQR1AgUFVCTElDIEtFWSBCTE9DSy0tLS0tClZlcnNpb246IEdudVBHIHYxLjQu\n" +
                               "MTAgKEdOVS9MaW51eCkKCm1RRU5CRXhGbWM0QkNBRG9RUU5OVzdRQTB5anNIWkhNVEY5RU9pMjJa\n" +
                               "TTR2QkQrK3E5TkNvME5OcTA1b0R1WDQKR3JUWFVGdk9KV1ZoVDNtdCtaaCtSQlBhS3NYVUd3ZEpw\n" +
                               "R1ZzMk4rbzZyMXF6TXorZ0paNEN3NDJZMzNRbjZJRgpPOTh4Mkh0TVNTUGk1QlVTYlExSnA3czYx\n" +
                               "MVlPMWtzTmtUOFpiSDAvSHErcUhSQzF6L1g4cVZNK3hlSGh4Ull6Cml6MEx2bytYZGMvNDUwRUEx\n" +
                               "dkRhNTRyM3Z5MUFIT0xhWDRpcmFzQ0I4N3NLV0YxcUp6UTQ5Zkw5SnRxZWVDOFAKYUtVbmlmQi9h\n" +
                               "UXNHdER2cGVVVWt6NDRPRjB5R2pjRTg3b1NHTTdWSEJxZmVKb0xubStzYmgyWkZaSnZEZWVJWAph\n" +
                               "ZzJSS3hpakJhcGlmR0xCcGkvc0p6c3pDekUrOFhFRDBCVEJBQkVCQUFHMEprTnNZWFZrYVc4Z1Ey\n" +
                               "aGxjblZpCmFXNXZJRHhqYkdGMVpHbHZRR2R2YjJkc1pTNWpiMjAraVFFNEJCTUJBZ0FpQlFKTVJa\n" +
                               "bk9BaHNEQmdzSkNBY0QKQWdZVkNBSUpDZ3NFRmdJREFRSWVBUUlYZ0FBS0NSRGJmeldDc0dtQWUw\n" +
                               "SzRCLzlZaEpGdXN3NGE5Q1JEYXU2dgpDVnJNRTlrVko4UmxocEpCZEY2V1pndGRPZlhsbzJycEVt\n" +
                               "Q1FRZ0lCRGJEeS9aQ3JHRWZDWlRIa0VLeXQrVVNpCndnUWY3NFRZZ0NzMTR0WmF5WHZKT3dENkIz\n" +
                               "QW1NYkRtQVFVM0ppdVRaMXIzZEZYV3BnUTE4RDI0YUEwcGVCOWMKbmcwbXc0enhGUW15b29paG14\n" +
                               "NWwvZmZ4UDFQUHNrL1kvV3F5ck5HQVhDUGxmRUFRdFN3bWRGYXNoVjYyZElEdwpOZXBMeTZSeE15\n" +
                               "TFRTL2ZvMExmSnEreWVjWjZkck91bTlkUnA3T0ZUOERSWmNqSTQ4eVM5VFNMd1Rtc0hHUm1uCkNO\n" +
                               "Nk1BWnBaK2lkVks5VEkveXVhOG4xQndNU3kwU3NGSjVpSG8wUFFHbSt5MHZxcDdGN2RCUlVCYWFw\n" +
                               "MGc0K3QKOTEyRQo9aFpYYwotLS0tLUVORCBQR1AgUFVCTElDIEtFWSBCTE9DSy0tLS0tCg==";

            try {
                // Upload public key
                Console.WriteLine("\n-----------Uploading public key-----------");
                AppsExtendedEntry keyEntry = service.UploadPublicKey(sampleKey);

                // Setting the parameters for a MailMonitor request
                MailMonitor monitor = new MailMonitor();
                monitor.BeginDate = new DateTime(2011, 6, 15);
                monitor.EndDate   = new DateTime(2011, 6, 30, 23, 20, 0);
                monitor.IncomingEmailMonitorLevel = MonitorLevel.FULL_MESSAGE;
                monitor.OutgoingEmailMonitorLevel = MonitorLevel.HEADER_ONLY;
                monitor.DraftMonitorLevel         = MonitorLevel.FULL_MESSAGE;
                monitor.ChatMonitorLevel          = MonitorLevel.FULL_MESSAGE;
                monitor.DestinationUserName       = destUsername;

                // Send the MailMonitor creation request
                Console.WriteLine("\n-----------Creating mail monitor-----------");
                MailMonitor monitorEntry = service.CreateMailMonitor(srcUsername, monitor);

                // Retrieve all MailMonitors for the source user
                Console.WriteLine("\n-----------Retrieving all mail monitors-----------");
                GenericFeed <MailMonitor> monitors = service.RetrieveMailMonitors(srcUsername);
                foreach (MailMonitor m in monitors.Entries)
                {
                    Console.WriteLine(m.DestinationUserName);
                }

                // Delete MailMonitor
                Console.WriteLine("\n-----------Deleting mail monitor-----------");
                service.DeleteMailMonitor(srcUsername, destUsername);

                // Create Account Info request
                Console.WriteLine("\n-----------Creating account info request-----------");
                AccountInfo accountInfoRequest = service.CreateAccountInfoRequest(srcUsername);
                Console.WriteLine("Request ID: " + accountInfoRequest.RequestId);

                // Retrieve Account Info request
                Console.WriteLine("\n-----------Retrieving account info request-----------");
                AccountInfo accountInfo = service.RetrieveAccountInfoRequest(srcUsername, accountInfoRequest.RequestId);
                Console.WriteLine("Status: " + accountInfo.Status);

                // Retrieve all Account Info requests from April 1st 2011
                Console.WriteLine("\n-----------Retrieving all account info requests-----------");
                GenericFeed <AccountInfo> accountInfoRequests = service.RetrieveAllAccountInfoRequests(new DateTime(2011, 4, 1));
                foreach (AccountInfo info in accountInfoRequests.Entries)
                {
                    Console.WriteLine(info.RequestId + " - " + info.Status);
                }

                // Delete Account Info request
                // This can only be done when the Status is COMPLETED or MARKED_DELETE
                //Console.WriteLine("\n-----------Deleting the account info request-----------");
                //service.DeleteAccountInfoRequest(srcUsername, accountInfoRequest.RequestId);

                // Setting the parameters for a MailboxDump request
                MailboxDumpRequest mailboxDumpRequest = new MailboxDumpRequest();
                mailboxDumpRequest.BeginDate      = new DateTime(2009, 6, 15);
                mailboxDumpRequest.EndDate        = new DateTime(2009, 6, 30, 23, 20, 0);
                mailboxDumpRequest.SearchQuery    = "in:chat";
                mailboxDumpRequest.PackageContent = MonitorLevel.FULL_MESSAGE;

                // Create Mailbox Dump request
                Console.WriteLine("\n-----------Creating mailbox dump request-----------");
                MailboxDumpRequest dumpRequest = service.CreateMailboxDumpRequest(srcUsername, mailboxDumpRequest);
                Console.WriteLine("Request ID: " + dumpRequest.RequestId);

                // Retrieve Mailbox Dump request
                Console.WriteLine("\n-----------Retrieving mailbox dump request-----------");
                MailboxDumpRequest checkRequest = service.RetrieveMailboxDumpRequest(srcUsername, dumpRequest.RequestId);
                Console.WriteLine("Status: " + dumpRequest.Status);

                // Retrieve all Mailbox Dump requests
                Console.WriteLine("\n-----------Retrieving all mailbox dump requests-----------");
                GenericFeed <MailboxDumpRequest> dumpRequests = service.RetrieveAllMailboxDumpRequests();
                foreach (MailboxDumpRequest dump in dumpRequests.Entries)
                {
                    Console.WriteLine(dump.RequestId + " - " + dump.Status);
                }

                // Delete Mailbox Dump request
                // This can only be done when the Status is COMPLETED or MARKED_DELETE
                //Console.WriteLine("\n-----------Deleting the mailbox dump request-----------");
                //service.DeleteMailboxDumpRequest(srcUsername, dumpRequest.RequestId);
            } catch (AppsException a) {
                Console.WriteLine("A Google Apps error occurred.");
                Console.WriteLine();
                Console.WriteLine("Error code: {0}", a.ErrorCode);
                Console.WriteLine("Invalid input: {0}", a.InvalidInput);
                Console.WriteLine("Reason: {0}", a.Reason);
            }
        }