Пример #1
0
 private void listView2_MouseClick(object sender, MouseEventArgs e)
 {
     ListView.SelectedIndexCollection s = listView2.SelectedIndices;
     if (s.Count > 0)
     {
         _editingFieldIndex = s[0];
         FieldToFind f = Program.FieldsList[_editingFieldIndex.Value];
         txtName.Text         = f.Name;
         txtRegexPattern.Text = f.Regex;
         numericUpDown1.Value = f.GroupNumber;
         cbRequired.Checked   = f.Required;
         btnNewAdd.Text       = "Save Changes";
         pnlNewField.Visible  = true;
     }
 }
Пример #2
0
        private void btnNewAdd_Click(object sender, EventArgs e)
        {
            switch (_editingFieldIndex)
            {
            case null when Program.FieldsList.Any(fli => fli.Name == txtName.Text):
                MessageBox.Show(
                    $@"There already is a field named {txtName.Text}. Field names should be unique.",
                    @"Gmail Scraper - add field",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation);

                return;

            case null:
                Program.FieldsList.Add(new FieldToFind
                {
                    Name        = txtName.Text,
                    Regex       = txtRegexPattern.Text,
                    GroupNumber = (int)numericUpDown1.Value,
                    Required    = cbRequired.Checked
                });
                break;

            default:
            {
                FieldToFind f = Program.FieldsList[_editingFieldIndex.Value];
                f.Name             = txtName.Text;
                f.Regex            = txtRegexPattern.Text;
                f.GroupNumber      = (int)numericUpDown1.Value;
                f.Required         = cbRequired.Checked;
                _editingFieldIndex = null;
                break;
            }
            }

            this.SetFieldsToFind();
            pnlNewField.Visible           = false;
            Settings.Default.FieldsToFind = JsonConvert.SerializeObject(Program.FieldsList);
            Settings.Default.Save();
        }
Пример #3
0
        public static async Task <List <string[]> > GetEmailsAndScrapeThem(string search,
                                                                           Action <string[]> onAdd)
        {
            var rows = new List <string[]>();

            UsersResource.MessagesResource.ListRequest request =
                GmailService.Users.Messages.List("me");
            request.MaxResults = int.MaxValue;
            request.Q          = search;
            IList <Message> messages = (await request.ExecuteAsync()).Messages;

            if (messages == null || messages.Count <= 0)
            {
                return(rows);
            }
            try
            {
                foreach (Message message in messages)
                {
                    if (Stop)
                    {
                        break;
                    }

                    UsersResource.MessagesResource.GetRequest req =
                        GmailService.Users.Messages.Get("me", message.Id);
                    Message mes = await req.ExecuteAsync();

                    string a;
                    if (!string.IsNullOrEmpty(mes.Payload.Parts[0].Body.Data))
                    {
                        a = mes.Payload.Parts[0].Body.Data;
                    }
                    else if (mes.Payload.Parts[0].Parts[0].Parts != null)
                    {
                        a = mes.Payload.Parts[0].Parts[0].Parts[1].Body.Data;
                    }
                    else
                    {
                        a = mes.Payload.Parts[0].Parts[1].Body.Data;
                    }

                    if (a == null)
                    {
                        continue;
                    }
                    string body    = Utf8.GetString(WebEncoders.Base64UrlDecode(a));
                    var    results = new string[FieldsList.Count];
                    for (var i = 0; i < FieldsList.Count; i++)
                    {
                        FieldToFind f       = FieldsList[i];
                        Match       rcMatch = Regex.Match(body, f.Regex, RegExOptions);
                        if (f.Required && !rcMatch.Success)
                        {
                            results[i] = "NOT FOUND";
                        }
                        else
                        {
                            results[i] = rcMatch.Groups[f.GroupNumber].Value;
                        }
                    }

                    onAdd(results);
                    rows.Add(results);
                }
            }
            catch
            {
                // ignored
            }

            return(rows);
        }