async Task FetchMessageSummariesAsync(bool print)
        {
            IList <IMessageSummary> fetched = null;

            do
            {
                try
                {
                    // fetch summary information for messages that we don't already have
                    int startIndex = messages.Count;

                    fetched = client.Inbox.Fetch(startIndex, -1, MessageSummaryItems.Full | MessageSummaryItems.UniqueId, cancel.Token);
                    break;
                }
                catch (ImapProtocolException)
                {
                    // protocol exceptions often result in the client getting disconnected
                    await ReconnectAsync();
                }
                catch (IOException)
                {
                    // I/O exceptions always result in the client getting disconnected
                    await ReconnectAsync();
                }
            } while (true);

            foreach (var message in fetched)
            {
                // this.logWriter.LogWrite(String.Format("print: {0}", print));
                if (print)
                {
                    this.logWriter.LogWrite(String.Format("{0}: new message: {1}", client.Inbox, message.Envelope.Subject));
                    // Run webdriver
                    foreach (var mailbox in message.Envelope.From.Mailboxes)
                    {
                        if (mailbox.Address == proSender)
                        {
                            string[] subjectPath = message.Envelope.Subject.Split('|');
                            if (subjectPath.Length >= 3)
                            {
                                if (subjectPath[2].Contains("Job Info to review"))
                                {
                                    // string submissionId
                                    string[] submissionPath = subjectPath[1].Trim().Split(' ');
                                    if (submissionPath.Length >= 2)
                                    {
                                        if (!autoRun.working)
                                        {
                                            autoRun.RunAuto(subjectPath[0].Trim(), submissionPath[1].Trim());
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                messages.Add(message);
            }
        }
Example #2
0
        private void BtnAuto1_Click(object sender, EventArgs e)
        {
            logWriter.filename = "logs.txt";
            if (this.textBox1.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải chọn file danh sách số điện thoại!", "Thông báo!", MessageBoxButtons.OK);
                return;
            }

            if (this.textBox2.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập nội dung tin nhắn!", "Thông báo!", MessageBoxButtons.OK);
                return;
            }

            logWriter.LogWrite("START ...");
            Loading(false);
            if (autoRun != null)
            {
                autoRun.Dispose();
            }
            autoRun = new AutoRun("zalotool");
            if (autoRun.loginStatus)
            {
                using (StreamReader reader = File.OpenText(this.textBox1.Text))
                {
                    logWriter.filename = string.Format("log-{0:yyyy-MM-dd_hh-mm-ss-tt}.txt", DateTime.Now);
                    string line = "";
                    string content = this.textBox2.Text;
                    string photo = this.textBox3.Text;
                    int index = 0;

                    while ((line = reader.ReadLine()) != null)
                    {
                        if (index > 0)
                        {
                            if (this.Configuration.Delay2Mess2Acc > 0)
                            {
                                Delay(1000 * this.Configuration.Delay2Mess2Acc);
                            }

                            if (this.Configuration.PauseAt > 0 && this.Configuration.PauseTime > 0)
                            {
                                if (index % this.Configuration.PauseAt == 0)
                                {
                                    if (this.Configuration.PauseTime > this.Configuration.Delay2Mess2Acc)
                                    {
                                        Delay(1000 * (this.Configuration.PauseTime - this.Configuration.Delay2Mess2Acc));
                                    }
                                }
                            }
                        }
                        List<String> input = new List<String>(line.Split("###".ToCharArray(), StringSplitOptions.RemoveEmptyEntries));
                        string phonenumber = input.First();
                        string[] paramsData = input.Skip(1).ToArray();
                        bool check = false;
                        try
                        {
                            string contentFormat = string.Format(content, paramsData);
                            check = autoRun.RunAuto(phonenumber, contentFormat, photo, this.Configuration.Delay2Mess1Acc, this.Configuration.MakeFriendWithStrangers);
                        }
                        catch (Exception error)
                        {
                            // MessageBox.Show(error.Message.ToString());
                        }
                        
                        string[] arr = new string[4];
                        ListViewItem itm;
                        arr[0] = phonenumber;
                        if (check)
                        {
                            arr[1] = "Thành công";
                            if (this.Configuration.LogWhenSuccessful)
                            {
                                logWriter.LogWrite(arr[0] + " ---------------------- true");
                            }
                        }
                        else
                        {
                            arr[1] = "Thất bại";
                            logWriter.LogWrite(arr[0] + " ---------------------- false");
                        }

                        itm = new ListViewItem(arr);
                        this.listView1.Items.Add(itm);
                        index++;
                    }
                    logWriter.filename = "logs.txt";
                }

                autoRun.Dispose();
                Loading(true);
                logWriter.LogWrite("END");
                MessageBox.Show("Hoàn thành gửi tin!", "Thông báo!", MessageBoxButtons.OK);
                return;
            }
            else
            {
                // autoRun.Dispose();
                Loading(true);
                MessageBox.Show("Đăng nhập không thành công! hãy đăng nhập zalo trên trình duyệt chrome và thực hiện lại!", "Login...", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            logWriter.LogWrite("End...");
        }