Beispiel #1
0
 private void processMessage(uint id, bool retry = true)
 {
     try
     {
         var message = client.GetMessage(id, FetchOptions.TextOnly);
         var data    = message.Body.Replace("\r\n", "\n");
         if (data.Contains("Here is the Steam Guard code you need to login to account "))
         {
             var match = new Regex("Here is the Steam Guard code you need to login to account (.+)\\:\n\n([A-Z0-9]{5})\n").Match(data);
             if (match.Success)
             {
                 if (Program.MailCodeRecieved(match.Groups[1].Value.ToLower(), match.Groups[2].Value))
                 {
                     deleteMail(id);
                 }
                 else
                 {
                     client.AddMessageFlags(id, null, MessageFlag.Flagged);
                     client.RemoveMessageFlags(id, null, MessageFlag.Seen);
                 }
             }
         }
     }
     catch (Exception e)
     {
         Logger.Error(PREFIX + "Unable to recieve mail " + e + ":");
         Logger.Error(e);
         if (retry)
         {
             Thread.Sleep(1000);
             processMessage(id, false);
         }
     }
 }
Beispiel #2
0
 private void MarkAsRead(ImapClient Client, uint id, bool isRead = true)
 {
     if (isRead)
     {
         Client.AddMessageFlags(id, null, MessageFlag.Seen);
     }
     else
     {
         Client.RemoveMessageFlags(id, null, MessageFlag.Seen);
     }
 }
        public static void Run()
        {
            // Create an instance of the ImapClient class
            ImapClient client = new ImapClient();

            // Specify host, username, password, port and SecurityOptions for your client
            client.Host            = "imap.gmail.com";
            client.Username        = "******";
            client.Password        = "******";
            client.Port            = 993;
            client.SecurityOptions = SecurityOptions.Auto;
            try
            {
                //ExStart:SetCustomFlag
                // Create a message
                MailMessage message = new MailMessage("*****@*****.**", "*****@*****.**", "subject", "message");

                //Append the message to mailbox
                string uid = client.AppendMessage(ImapFolderInfo.InBox, message);

                //Add custom flags to the added messge
                client.AddMessageFlags(uid, ImapMessageFlags.Keyword("custom1") | ImapMessageFlags.Keyword("custom1_0"));

                //Retreive the messages for checking the presence of custom flag
                client.SelectFolder(ImapFolderInfo.InBox);

                ImapMessageInfoCollection messageInfos = client.ListMessages();
                foreach (var inf in messageInfos)
                {
                    ImapMessageFlags[] flags = inf.Flags.Split();

                    if (inf.ContainsKeyword("custom1"))
                    {
                        Console.WriteLine("Keyword found");
                    }
                }

                //ExEnd:SetCustomFlag

                Console.WriteLine("Setting Custom Flag to Message example executed successfully!");
                client.Dispose();
            }
            catch (Exception ex)
            {
                Console.Write(Environment.NewLine + ex);
            }
        }
Beispiel #4
0
        public ActionResult MarkEmailAsRead(uint EmailUDI, string Mailbox)
        {
            if (CheckLogin)
            {
                using (ImapClient Client = QLogin())
                {
                    try
                    {
                        MessageFlag[] AddFlags = new MessageFlag[] { MessageFlag.Seen };

                        Client.AddMessageFlags(EmailUDI, Mailbox, AddFlags);
                        return(OkSuccess());
                    }
                    catch (Exception e)
                    {
                        return(BadRequestFail(e.Message));
                    }
                }
            }
            return(AccessDenied());
        }
    private void ChangeReadStatus(string msgSequenceNumber, string status)
    {
        try
        {
            // initialize imap client
            ImapClient client = new ImapClient();
            client.Host = txtHost.Text;
            client.Port = int.Parse(txtPort.Text);
            client.Username = txtUsername.Text;
            client.Password = Session["Password"].ToString();

            // SSL Settings
            if (chSSL.Checked == true)
            {
                client.EnableSsl = true;
                client.SecurityMode = ImapSslSecurityMode.Implicit;
            }

            // connect to imap server and login
            client.Connect(true);
            client.SelectFolder(ImapFolderInfo.InBox);
            lblMessage.ForeColor = Color.Green;
            lblMessage.Text = "Successfully connected to Imap Mail server.<br><hr>";

            // change the message status
            if (status == "1") // mark as read
                client.AddMessageFlags(int.Parse(msgSequenceNumber), ImapMessageFlags.IsRead);
            else // mark as un-read
                client.RemoveMessageFlags(int.Parse(msgSequenceNumber), ImapMessageFlags.IsRead);

            client.Disconnect();
        }
        catch (Exception ex)
        {
            lblMessage.ForeColor = Color.Red;
            lblMessage.Text = "Error: " + ex.Message;
        }
    }
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        using (ImapClient imap = new ImapClient("<ADDRESS> (e.g. imap.gmail.com)"))
        {
            imap.Connect();
            imap.Authenticate("<USERNAME>", "<PASSWORD>");

            // Select INBOX folder.
            imap.SelectInbox();

            // Add "Draft" flag to first message.
            imap.AddMessageFlags(1, ImapMessageFlags.Draft);

            // Get first message flags and display them.
            // Notice the presence of "Draft" flag.
            IList <string> flags = imap.GetMessageFlags(1);
            foreach (string flag in flags)
            {
                Console.WriteLine(flag);
            }

            // Remove "Draft" flag from first message.
            imap.RemoveMessageFlags(1, ImapMessageFlags.Draft);

            Console.WriteLine(new string('-', 10));

            // Again, get first message flags and display them.
            // Notice the absence of "Draft" flag.
            flags = imap.GetMessageFlags(1);
            foreach (string flag in flags)
            {
                Console.WriteLine(flag);
            }
        }
    }
Beispiel #7
0
        public ActionResult DeleteEmail(uint EmailUDI, string Mailbox)
        {
            if (CheckLogin)
            {
                using (ImapClient Client = QLogin())
                {
                    try
                    {
                        MessageFlag[] AddFlags = new MessageFlag[] { MessageFlag.Deleted };

                        Client.AddMessageFlags(EmailUDI, Mailbox, AddFlags);
                        //Client.DeleteMessage(EmailUDI);
                        Client.Expunge(Mailbox);
                        return(OkSuccess());
                    }
                    catch (Exception e)
                    {
                        return(BadRequestFail(e.Message));
                    }
                }
            }
            return(AccessDenied());
        }
Beispiel #8
0
        bool handleMessage(ImapClient client, uint uid, MailMessage msg)
        {
            client.AddMessageFlags(uid, null, MessageFlag.Seen);

            foreach (var file in msg.Attachments)
            {
                string solution = file.toString();

                string header          = solution;
                int    firstLineLength = solution.IndexOfAny(Util.LineEndings);
                if (firstLineLength > 0)
                {
                    header = solution.Substring(0, firstLineLength);
                }

                DateTime now = DateTime.Now;

                // TODO[szx][0]: handle deserialization failure.
                Submission submission = Util.Json.fromJsonString <Submission>(header);
                submission.email = msg.From.Address;
                submission.date  = Util.friendlyDateTime(now);

                Problem problem;
                if (!page.rank.problems.TryGetValue(submission.problem, out problem))
                {
                    continue;
                }
                Instance instance;
                if (!problem.instances.TryGetValue(submission.instance, out instance))
                {
                    continue;
                }

                string dir = CommonCfg.ArchiveDir + submission.problem + "/";
                Directory.CreateDirectory(dir);
                string filePath = dir + Util.compactDateTime(now) + "-" + submission.instance;
                File.WriteAllText(filePath, solution);

                if (page.checkers.TryGetValue(problem.checkerPath, out Checker.Check check))
                {
                    submission.obj = check(solution);
                }
                else if (File.Exists(problem.checkerPath))
                {
                    string obj = Util.runRead(problem.checkerPath, dir + submission.instance + " " + filePath);
                    if (!double.TryParse(obj, out submission.obj))
                    {
                        File.Delete(filePath); continue;
                    }
                }
                else
                {
                    submission.obj = 0;
                }

                if (submission.obj <= 0)
                {
                    continue;
                }                                      // infeasible or trivial solution.

                Util.run("git", "add " + filePath);

                instance.results.Add(new Result {
                    path = filePath, header = submission
                });

                if (instance.results.Count > CommonCfg.MaxResultsCountPerInstance)
                {
                    instance.results.Remove(problem.minimize ? instance.results.Max : instance.results.Min);
                }
            }
            client.DeleteMessage(uid);

            return(true);
        }
Beispiel #9
0
 public ActionResult SetEmailFlags(uint EmailUDI, EmailFlags EmailFlags, string Mailbox)
 {
     if (CheckLogin)
     {
         using (ImapClient Client = QLogin())
         {
             try
             {
                 List <MessageFlag> AddFlags    = new List <MessageFlag>();
                 List <MessageFlag> RemoveFlags = new List <MessageFlag>();
                 if (EmailFlags.Seen != null)
                 {
                     if (EmailFlags.Seen.Value == true)
                     {
                         AddFlags.Add(MessageFlag.Seen);
                     }
                     else
                     {
                         RemoveFlags.Add(MessageFlag.Seen);
                     }
                 }
                 if (EmailFlags.Deleted != null)
                 {
                     if (EmailFlags.Deleted.Value == true)
                     {
                         AddFlags.Add(MessageFlag.Deleted);
                     }
                     else
                     {
                         RemoveFlags.Add(MessageFlag.Deleted);
                     }
                 }
                 if (EmailFlags.Draft != null)
                 {
                     if (EmailFlags.Draft.Value == true)
                     {
                         AddFlags.Add(MessageFlag.Draft);
                     }
                     else
                     {
                         RemoveFlags.Add(MessageFlag.Draft);
                     }
                 }
                 if (EmailFlags.Recent != null)
                 {
                     if (EmailFlags.Recent.Value == true)
                     {
                         AddFlags.Add(MessageFlag.Recent);
                     }
                     else
                     {
                         RemoveFlags.Add(MessageFlag.Recent);
                     }
                 }
                 if (EmailFlags.Flagged != null)
                 {
                     if (EmailFlags.Flagged.Value == true)
                     {
                         AddFlags.Add(MessageFlag.Flagged);
                     }
                     else
                     {
                         RemoveFlags.Add(MessageFlag.Flagged);
                     }
                 }
                 if (EmailFlags.Answered != null)
                 {
                     if (EmailFlags.Answered.Value == true)
                     {
                         AddFlags.Add(MessageFlag.Answered);
                     }
                     else
                     {
                         RemoveFlags.Add(MessageFlag.Answered);
                     }
                 }
                 Client.AddMessageFlags(EmailUDI, Mailbox, AddFlags.ToArray());
                 Client.RemoveMessageFlags(EmailUDI, Mailbox, RemoveFlags.ToArray());
                 return(OkSuccess());
             }
             catch (Exception e)
             {
                 return(BadRequestFail(e.Message));
             }
         }
     }
     return(AccessDenied());
 }