public ImapMessageStatusChangedEventArgs(ImapMessageInfo[] messages)
        {
            if (messages == null)
            throw new ArgumentNullException("messages");

              this.Messages = messages;
        }
        public ImapMessageDeletedException(string message, ImapMessageInfo deletedMessage)
            : base(message)
        {
            if (deletedMessage == null)
            throw new ArgumentNullException("deletedMessage");

              this.deletedMessage = deletedMessage;
        }
Exemple #3
0
        public static void Run()
        {
            try
            {
                // ExStart:RetrieveExtraParametersAsSummaryInformation
                using (ImapClient client = new ImapClient("host.domain.com", "username", "password"))
                {
                    MailMessage message = new MailMessage("*****@*****.**", "*****@*****.**", "EMAILNET-38466 - " + Guid.NewGuid().ToString(), "EMAILNET-38466 Add extra parameters for UID FETCH command");

                    // append the message to the server
                    string uid = client.AppendMessage(message);

                    // wait for the message to be appended
                    Thread.Sleep(5000);

                    // Define properties to be fetched from server along with the message
                    string[] messageExtraFields = new string[] { "X-GM-MSGID", "X-GM-THRID" };

                    // retreive the message summary information using it's UID
                    ImapMessageInfo messageInfoUID = client.ListMessage(uid, messageExtraFields);

                    // retreive the message summary information using it's sequence number
                    ImapMessageInfo messageInfoSeqNum = client.ListMessage(1, messageExtraFields);

                    // List messages in general from the server based on the defined properties
                    ImapMessageInfoCollection messageInfoCol = client.ListMessages(messageExtraFields);

                    ImapMessageInfo messageInfoFromList = messageInfoCol[0];

                    // verify that the parameters are fetched in the summary information
                    foreach (string paramName in messageExtraFields)
                    {
                        Console.WriteLine(messageInfoFromList.ExtraParameters.ContainsKey(paramName));
                        Console.WriteLine(messageInfoUID.ExtraParameters.ContainsKey(paramName));
                        Console.WriteLine(messageInfoSeqNum.ExtraParameters.ContainsKey(paramName));
                    }
                }
                // ExEnd:RetrieveExtraParametersAsSummaryInformation
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }
        }
        private void TestMessage(int existMessageCount, ImapCapability[] capabilities, ImapSequenceSet sequenceOrUidSet, Action<ImapPseudoServer, ImapMessageInfoBase, ImapMessageInfo[]> action)
        {
            TestUtils.TestAuthenticated(capabilities, delegate(ImapPseudoServer server, ImapClient client) {
            // LIST
            server.EnqueueTaggedResponse("* LIST () \".\" INBOX\r\n" +
                                     "$tag OK done\r\n");
            // SELECT
            server.EnqueueTaggedResponse(string.Format("* EXISTS {0}\r\n", existMessageCount) +
                                     "* OK [UIDVALIDITY 1]\r\n" +
                                     "$tag OK done\r\n");

            using (var inbox = client.OpenInbox()) {
              server.DequeueRequest(); // LIST
              server.DequeueRequest(); // SELECT

              var messages = new ImapMessageInfo[0];

              if (0 < existMessageCount) {
            // NOOP
            server.EnqueueTaggedResponse("$tag OK done\r\n");
            // FETCH
            var fetchResp = new StringBuilder();

            for (var seq = 1; seq <= existMessageCount; seq++) {
              fetchResp.AppendFormat("* FETCH {0} (UID {0})\r\n", seq);
            }

            fetchResp.Append("$tag OK done\r\n");

            server.EnqueueTaggedResponse(fetchResp.ToString());

            messages = inbox.GetMessages().ToArray();

            server.DequeueRequest(); // NOOP
            server.DequeueRequest(); // FETCH
              }

              try {
            var messageSet = new MessageSet(inbox, sequenceOrUidSet);

            Assert.AreSame(messageSet.Client, client);
            Assert.AreSame(messageSet.Mailbox, inbox);
            Assert.AreEqual(1L, messageSet.UidValidity);

            action(server, messageSet, messages);
              }
              finally {
            if (inbox.IsOpen)
              // CLOSE
              server.EnqueueTaggedResponse("$tag OK done\r\n");
              }
            }
              });
        }
        internal ImapMessageInfo ToMessageInfo(ImapMessageAttribute message, bool hasStaticAttr, bool hasDynamicAttr)
        {
            ImapMessageInfo info;

              if (messages.Contains(message.Uid)) {
            info = messages[message.Uid];
            info.Sequence = message.Sequence;
              }
              else {
            info = new ImapMessageInfo(this, message.Uid, message.Sequence);

            messages.Add(info);
              }

              if (hasStaticAttr)
            info.StaticAttribute = message.GetStaticAttributeImpl();
              if (hasDynamicAttr)
            info.DynamicAttribute = message.GetDynamicAttributeImpl();

              return info;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="MessageViewModel"/> class.
 /// </summary>
 /// <param name="msg">The MSG.</param>
 public MessageViewModel(ImapMessageInfo msg)
 {
     Message = msg;
 }
Exemple #7
0
        static void Main(string[] args)
        {
            // try {
            unzipDir      = unzipDir.Substring(1);
            downloadDir   = downloadDir.Substring(1);
            websiteDir    = websiteDir.Substring(1);
            pathForBackup = pathForBackup.Substring(1);

            Console.WriteLine("Before we start, let's check paths quickly");
            Console.WriteLine(unzipDir);
            Console.WriteLine(downloadDir);
            Console.WriteLine(websiteDir);
            Console.WriteLine(pathForBackup);

            using (Imap client = new Imap())
            {
                // connect and log in
                Rebex.Licensing.Key = "==Ao6cV2HIJ+/xrOQTyfD2colAHzfn/7uQQVjmgqnqeYlI==";
                client.Connect("imap.mail.ru", SslMode.Implicit);
                // authenticate
                //  client.Login("*****@*****.**", "6ataalimuly");
                client.Login("*****@*****.**", "qwertymnbvcx");

                // select working folder
                client.SelectFolder("Inbox");

                // get the MessageInfo (without message body and attachments
                // but with info whether the message contains attachments)
                ImapMessageInfo messageInfo = client.GetMessageInfo(client.CurrentFolder.TotalMessageCount, ImapListFields.Envelope | ImapListFields.MessageStructure);
                Console.WriteLine("Reading mail sub. '{0}' (attachments = {1})...", messageInfo.Subject, messageInfo.HasAttachment);

                // set the progress event handler
                client.TransferProgress +=
                    new ImapTransferProgressEventHandler(client_TransferProgress);

                // get the full message (including attachments)

                MailMessage message = client.GetMailMessage(client.CurrentFolder.TotalMessageCount);
                attachments = new List <string>();
                string attachmentName = string.Empty;


                FileStream fs2;
                Console.WriteLine();
                foreach (Attachment attachment in message.Attachments)
                {
                    Console.WriteLine(downloadDir + attachment.FileName);
                    fs2 = File.Create(downloadDir + attachment.FileName);

                    fs2.Close();
                    Console.WriteLine("Attachment downloaded to path: " + downloadDir.Substring(1) + attachment.FileName /*Path.GetFullPath(attachment.FileName)*/);

                    //if
                    attachment.Save(/*attachment.FileName*/ downloadDir + attachment.FileName);
                    attachments.Add(attachment.FileName);
                    attachmentName = attachment.FileName;
                }


                //    File.Copy(attachmentName, Path.Combine(@down));

                Console.WriteLine("\nMail read - ({0} attachaments)", message.Attachments.Count);



                newNuGet = attachmentName;

                if (String.Compare(newNuGet, currentNuGet) > 0)
                {
                    Console.WriteLine();
                    Console.WriteLine("Current NuGet: " + currentNuGet);
                    Console.WriteLine("Replacing current " + currentNuGet + " with " + newNuGet);

                    UnzipNuGetPackage();

                    BackUp();

                    ReplaceWithNewerVersion();

                    //replace string in .txt file (currentNuGet) with newNuGet
                    using (var fs = new FileStream(@"current_version.txt", FileMode.Truncate))
                    {
                    }

                    File.WriteAllText("current_version.txt", newNuGet);

                    currentNuGet = newNuGet;

                    Console.WriteLine("Current NuGet: " + currentNuGet);

                    Console.WriteLine("Everything is done!");
                }
                else
                {
                    Console.WriteLine();
                    Console.WriteLine("Current " + currentNuGet + " is up-to-date");
                }
            }

            //   }

            /*    catch (Exception e)
             *  {
             *      Console.WriteLine(e.Message);
             *  }*/
            Console.ReadKey();
        }
        internal void RaiseMessageStatusChanged(ImapMessageInfo[] messages)
        {
            var ev = MessageStatusChanged;

              if (ev != null)
            ev(this, new ImapMessageStatusChangedEventArgs(messages));
        }
 public ImapMessageDeletedException(ImapMessageInfo deletedMessage)
     : this(string.Format("message has been deleted (UID: {0})", deletedMessage.Uid), deletedMessage)
 {
 }
        public void TestGetMessages()
        {
            var selectResp =
            "* 5 EXISTS\r\n" +
            "* OK [UIDVALIDITY 23]\r\n" +
            "$tag OK [READ-WRITE] done\r\n";

              TestUtils.TestOpenedMailbox("INBOX", selectResp, delegate(ImapPseudoServer server, ImapOpenedMailboxInfo mailbox) {
            var messages = mailbox.GetMessages();

            Assert.AreEqual(5L, mailbox.ExistMessageCount);

            var enumeratedMessages = new ImapMessageInfo[4];

            using (var enumerator = messages.GetEnumerator()) {
              // NOOP
              server.EnqueueTaggedResponse("* 5 EXPUNGE\r\n" +
                                       "* 4 EXISTS\r\n" +
                                       "$tag OK done\r\n");
              // FETCH
              server.EnqueueTaggedResponse("* FETCH 1 (UID 3)\r\n" +
                                       "* FETCH 2 (UID 5)\r\n" +
                                       "* FETCH 3 (UID 7)\r\n" +
                                       "* FETCH 4 (UID 9)\r\n" +
                                       "$tag OK done\r\n");

              Assert.IsTrue(enumerator.MoveNext());

              Assert.That(server.DequeueRequest(), Text.EndsWith("NOOP\r\n"));
              Assert.That(server.DequeueRequest(), Text.EndsWith("FETCH 1:4 (UID)\r\n"));

              Assert.AreEqual(4L, mailbox.ExistMessageCount);

              Assert.IsNotNull(enumerator.Current, "#0 non-null");
              Assert.AreEqual(3L, enumerator.Current.Uid, "#0 uid");
              Assert.AreEqual(1L, enumerator.Current.Sequence, "#0 seq");

              enumeratedMessages[0] = enumerator.Current;

              Assert.IsTrue(enumerator.MoveNext());

              Assert.IsNotNull(enumerator.Current, "#1 non-null");
              Assert.AreEqual(5L, enumerator.Current.Uid, "#1 uid");
              Assert.AreEqual(2L, enumerator.Current.Sequence, "#1 seq");

              enumeratedMessages[1] = enumerator.Current;

              Assert.IsTrue(enumerator.MoveNext());

              Assert.IsNotNull(enumerator.Current, "#2 non-null");
              Assert.AreEqual(7L, enumerator.Current.Uid, "#2 uid");
              Assert.AreEqual(3L, enumerator.Current.Sequence, "#2 seq");

              enumeratedMessages[2] = enumerator.Current;

              Assert.IsTrue(enumerator.MoveNext());

              Assert.IsNotNull(enumerator.Current, "#3 non-null");
              Assert.AreEqual(9L, enumerator.Current.Uid, "#3 uid");
              Assert.AreEqual(4L, enumerator.Current.Sequence, "#3 seq");

              enumeratedMessages[3] = enumerator.Current;

              Assert.IsFalse(enumerator.MoveNext());
            }

            /*
             * re-enumerate
             */
            Assert.AreEqual(4L, mailbox.ExistMessageCount);

            using (var enumerator = messages.GetEnumerator()) {
              // NOOP
              server.EnqueueTaggedResponse("* 2 EXPUNGE\r\n" +
                                       "* 1 EXPUNGE\r\n" +
                                       "$tag OK done\r\n");
              // FETCH
              server.EnqueueTaggedResponse("* FETCH 1 (UID 7)\r\n" +
                                       "* FETCH 2 (UID 9)\r\n" +
                                       "$tag OK done\r\n");

              Assert.IsTrue(enumerator.MoveNext());

              Assert.That(server.DequeueRequest(), Text.EndsWith("NOOP\r\n"));
              Assert.That(server.DequeueRequest(), Text.EndsWith("FETCH 1:2 (UID)\r\n"));

              Assert.AreEqual(2L, mailbox.ExistMessageCount);

              Assert.IsNotNull(enumerator.Current, "#0 non-null");
              Assert.AreEqual(7L, enumerator.Current.Uid, "#0 uid");
              Assert.AreEqual(1L, enumerator.Current.Sequence, "#0 seq");

              Assert.AreSame(enumeratedMessages[2], enumerator.Current, "returns same instance #0");

              Assert.IsTrue(enumerator.MoveNext());

              Assert.IsNotNull(enumerator.Current, "#1 non-null");
              Assert.AreEqual(9L, enumerator.Current.Uid, "#1 uid");
              Assert.AreEqual(2L, enumerator.Current.Sequence, "#1 seq");

              Assert.AreSame(enumeratedMessages[3], enumerator.Current, "returns same instance #1");

              Assert.IsFalse(enumerator.MoveNext());
            }
              });
        }
Exemple #11
0
        /// <summary>
        /// Deletes the message.
        /// </summary>
        /// <param name="msg">The MSG.</param>
        /// <returns></returns>
        public async Task DeleteMessage(ImapMessageInfo msg)
        {
            await _imap.SelectFolder("INBOX");

            await _imap.SetFlag(msg.Message.Uid, '+', @"\Deleted");
        }