public async Task ListLabels() { UserCredential credential; using (var stream = new FileStream("client_secrets_desktop.json", FileMode.Open, FileAccess.Read)) { credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets, new[] { GmailService.Scope.GmailReadonly }, "user", CancellationToken.None); } var service = new GmailService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = "Gmail Test", }); try { ListLabelsResponse response = service.Users.Labels.List("me").Execute(); foreach (Label label in response.Labels.OrderBy(p => p.Name)) { Console.WriteLine(label.Id + " - " + label.Name); } } catch (Exception e) { Console.WriteLine("An error occurred: " + e.Message); } }
public IList <Label> GetLabelsForMessage(string Id) { var request = _service.Users.Labels.List(Id); List <Label> labelList = new List <Label>(); ListLabelsResponse response = request.Execute(); labelList.AddRange(response.Labels); return(labelList); }
/// <summary> /// List the labels in the user's mailbox. /// </summary> /// <param name="service">Gmail API service instance.</param> /// <param name="userId">User's email address. The special value "me" /// can be used to indicate the authenticated user.</param> public static void ListLabels(GmailService service, String userId) { try { ListLabelsResponse response = service.Users.Labels.List(userId).Execute(); foreach (Label label in response.Labels) { Console.WriteLine(label.Id + " - " + label.Name); } } catch (Exception e) { Console.WriteLine("An error occurred: " + e.Message); } }
/// <summary> /// List the labels in the user's mailbox. /// </summary> /// <param name="service">Gmail API service instance.</param> /// <param name="userId">User's email address. The special value "me" /// can be used to indicate the authenticated user.</param> public void ListLabels() { try { ListLabelsResponse response = this.Service.Users.Labels.List(this.UserId).Execute(); foreach (Label _label in response.Labels) { Console.WriteLine(_label.Id + " - " + _label.Name); } } catch (Exception e) { Console.WriteLine("An error occurred: " + e.Message); } }
/// <summary> /// List the labels in the user's mailbox. /// <param name="userId">User's email address. The special value "me" can be used to indicate the authenticated user.</param> /// </summary> public IList <Label> GetLabels() { IList <Label> Labels = new List <Label>(); try { ListLabelsResponse response = GmailService.Users.Labels.List("me").Execute(); Labels = response.Labels; } catch (Exception ex) { Console.WriteLine($"An error occurred: {ex.Message}"); } return(Labels); }
/// <summary> /// List the labels in the user's mailbox. /// </summary> /// <param name="service">Gmail API service instance.</param> /// <param name="userId">User's email address. The special value "me" /// can be used to indicate the authenticated user.</param> public async Task <List <string> > GetLabels(object service, string userId) { List <string> labels = new List <string>(); try { ListLabelsResponse response = await((GmailService)service).Users.Labels.List(userId).ExecuteAsync(); foreach (Label label in response.Labels) { labels.Add(label.Id); } } catch //(Exception e) { //Console.WriteLine("An error occurred: " + e.Message); } return(labels); }
//public IList<Google.Apis.Gmail.v1.Data.Label> GetGmailLabels() //{ // // Define parameters of request. // UsersResource.LabelsResource.ListRequest request = service.Users.Labels.List(userId); // // List labels. // IList<Label> labels = request.Execute().Labels; // return labels; //} /// <summary> /// List the labels in the user's mailbox. /// </summary> /// <param name="service">Gmail API service instance.</param> /// <param name="userId">User's email address. The special value "me" /// can be used to indicate the authenticated user.</param> public Dictionary <string, Label> GetLabels(String userId) { Dictionary <string, Label> result = new Dictionary <string, Label>(); try { ListLabelsResponse response = service.Users.Labels.List(userId).Execute(); foreach (Label label in response.Labels) { string labelId = label.Id; result[labelId] = new Label(); result[labelId].Name = label.Name; } } catch (Exception e) { Console.WriteLine("An error occurred: " + e.Message); } return(result); }
/// <summary> /// Asynchronous method used to get account statistics /// </summary> private async void UpdateStatistics() { // gets inbox message count int unread = (int)Box.ThreadsUnread; int total = (int)Box.ThreadsTotal; // builds the chart if (total == 0) { UI.chartUnreadMails.Width = 0; UI.chartTotalMails.Width = 0; } else { const int MAXIMUM_SCALE = 100; bool INBOX_FULL = total > MAXIMUM_SCALE; int scale = INBOX_FULL ? total : MAXIMUM_SCALE; UI.chartUnreadMails.Width = INBOX_FULL && unread == 1 ? 1 : (unread * UI.chartInbox.Width) / scale; UI.chartTotalMails.Width = (total * UI.chartInbox.Width) / scale; } // updates the tooltip informations UI.tip.SetToolTip(UI.chartUnreadMails, unread + " " + (unread > 1 ? Translation.unreadMessages : Translation.unreadMessage)); UI.tip.SetToolTip(UI.chartTotalMails, total + " " + (total > 1 ? Translation.messages : Translation.message)); // updates the draft informations ListDraftsResponse drafts = await Api.Users.Drafts.List("me").ExecuteAsync(); UI.labelTotalDrafts.Text = drafts.Drafts != null?drafts.Drafts.Count.ToString() : "0"; // updates the label informations ListLabelsResponse labels = await Api.Users.Labels.List("me").ExecuteAsync(); UI.labelTotalLabels.Text = labels.Labels != null?labels.Labels.Count.ToString() : "0"; }
public static List <Message> GetMail() { UserCredential credential; string startupPath = AppDomain.CurrentDomain.BaseDirectory; using (var stream = new System.IO.FileStream(startupPath + @"credentials.json", System.IO.FileMode.Open, System.IO.FileAccess.Read)) { // The file token.json stores the user's access and refresh tokens, and is created // automatically when the authorization flow completes for the first time. string credPath = startupPath + @"token.json"; credential = GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(stream).Secrets, Scopes, "user", CancellationToken.None, new FileDataStore(credPath, true)).Result; Console.WriteLine("Credential file saved to: " + credPath); } // Create Gmail API service. var service = new GmailService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = "My Budget", }); ListLabelsResponse response = service.Users.Labels.List("me").Execute(); List <Label> _labels = new List <Label>(); foreach (Label label in response.Labels) { Label _label = new Label(); // if(label.Type == "user") // { _label.Id = label.Id; _label.Name = label.Name; //} _labels.Add(_label); } String query = ""; List <Message> result = new List <Message>(); // Define parameters of request. UsersResource.MessagesResource.ListRequest request = service.Users.Messages.List("me"); request.Q = query; request.MaxResults = 5000; request.LabelIds = "Label_2500152685495181559"; // var serv = service.Users.Messages try { ListMessagesResponse response2 = request.Execute(); result.AddRange(response2.Messages); //request.PageToken = response2.NextPageToken; //foreach (var item in result) for (int i = 0; i < result.Count; i++) { var m = service.Users.Messages.Get("me", result[i].Id).Execute(); //if (m.LabelIds.Contains("IMPORTANT") && m.LabelIds.Contains("Label_2500152685495181559")) //{ var d = m.Snippet; var model = new SMSData(); string[] msg = d.Split(new string[] { "Message text: " }, StringSplitOptions.None); model.SMSText = d; // msg[1]; string sa = @"""" + "/Date(" + m.InternalDate + "-0530 )/" + @""""; model.Date = DateTime.Now; // JsonConvert.DeserializeObject<DateTime>(sa); //model.Label = _labels.Where(x => x.Id == m.LabelIds) if (db.SMSData.Count() > 0) { DateTime prevDate = db.SMSData.ToList().OrderByDescending(x => x.Date.Value).Select(x => x.Date.Value).First(); if (model.Date > prevDate) { if (d.Contains("KOTAK") || d.Contains("XXXX467304")) { model.BankName = "Kotak Mahindra Bank"; if (d.Contains("credited ")) { model.TransactionType = "Credit"; // resultString = Regex.Match(subjectString, @"\d+").Value; try { string[] msg1 = msg[1].Split(new string[] { "credited Rs." }, StringSplitOptions.None); string[] msg2 = msg1[1].Split(new string[] { "on" }, StringSplitOptions.None); BankAccounts ba = new BankAccounts(); ba = db.BankAccounts.Where(x => x.BankName.Contains("KOTAK")).FirstOrDefault(); ba.Balance += Convert.ToDouble(msg2[0]); model.Amount = msg2[0]; db.Entry(ba).State = EntityState.Modified; } catch (Exception ex) { Console.WriteLine("An error occurred: " + ex.Message); } } else if (d.Contains("debited")) { try { model.TransactionType = "Debit"; string[] msg1 = msg[1].Split(new string[] { "has been debited" }, StringSplitOptions.None); // string[] msg2 = msg1[1].Split(new string[] { "on" }, StringSplitOptions.None); BankAccounts ba = new BankAccounts(); ba = db.BankAccounts.Where(x => x.BankName.Contains("KOTAK")).FirstOrDefault(); ba.Balance -= Convert.ToDouble(msg1[0]); model.Amount = msg1[0]; db.Entry(ba).State = EntityState.Modified; } catch (Exception ex) { Console.WriteLine("An error occurred: " + ex.Message); } } db.SaveChanges(); } else if (d.Contains("ICICI") || d.Contains("XX3416") || d.Contains("XX416")) { model.BankName = "ICICI Bank"; if (d.Contains("credited ")) { try { model.TransactionType = "Credit"; string[] msg1 = msg[1].Split(new string[] { "credited Rs." }, StringSplitOptions.None); string[] msg2 = msg1[1].Split(new string[] { "on" }, StringSplitOptions.None); BankAccounts ba = new BankAccounts(); ba = db.BankAccounts.Where(x => x.BankName.Contains("ICICI") && x.AccountType == 0).FirstOrDefault(); ba.Balance += Convert.ToDouble(msg2[0]); model.Amount = msg2[0]; db.Entry(ba).State = EntityState.Modified; } catch (Exception ex) { Console.WriteLine("An error occurred: " + ex.Message); } } else if (d.Contains("debited")) { model.TransactionType = "Debit"; if (msg[1].Contains("INR")) { try { string[] msg1 = msg[1].Split(new string[] { "INR" }, StringSplitOptions.None); string[] msg2 = msg1[1].Split(new string[] { "on" }, StringSplitOptions.None); BankAccounts ba = new BankAccounts(); ba = db.BankAccounts.Where(x => x.BankName.Contains("ICICI") && x.AccountType == 0).FirstOrDefault(); ba.Balance -= Convert.ToDouble(msg2[0]); model.Amount = msg2[0]; db.Entry(ba).State = EntityState.Modified; } catch (Exception ex) { Console.WriteLine("An error occurred: " + ex.Message); } } else if (msg[1].Contains("has been debited")) { try { string[] msg1 = msg[1].Split(new string[] { "has been debited for Rs." }, StringSplitOptions.None); string[] msg2 = msg1[1].Split(new string[] { "on" }, StringSplitOptions.None); BankAccounts ba = new BankAccounts(); ba = db.BankAccounts.Where(x => x.BankName.Contains("ICICI") && x.AccountType == 0).FirstOrDefault(); ba.Balance -= Convert.ToDouble(msg2[0]); model.Amount = msg2[0]; db.Entry(ba).State = EntityState.Modified; } catch (Exception ex) { Console.WriteLine("An error occurred: " + ex.Message); } } } db.SaveChanges(); } else if (d.Contains("Union") || d.Contains("X4541") || d.Contains("**24541")) { model.BankName = "Union Bank"; if (d.Contains("credited ")) { try { model.TransactionType = "Credit"; // resultString = Regex.Match(subjectString, @"\d+").Value; string[] msg1 = msg[1].Split(new string[] { "credited Rs." }, StringSplitOptions.None); string[] msg2 = msg1[1].Split(new string[] { "on" }, StringSplitOptions.None); BankAccounts ba = new BankAccounts(); ba = db.BankAccounts.Where(x => x.BankName.Contains("Union") && x.AccountType == 0).FirstOrDefault(); ba.Balance += Convert.ToDouble(msg2[0]); model.Amount = msg2[0]; db.Entry(ba).State = EntityState.Modified; } catch (Exception ex) { Console.WriteLine("An error occurred: " + ex.Message); } } else if (d.Contains("debited")) { try { model.TransactionType = "Debit"; string[] msg1 = msg[1].Split(new string[] { "is debited for Rs." }, StringSplitOptions.None); string[] msg2 = msg1[1].Split(new string[] { "on" }, StringSplitOptions.None); BankAccounts ba = new BankAccounts(); ba = db.BankAccounts.Where(x => x.BankName.Contains("Union") && x.AccountType == 0).FirstOrDefault(); ba.Balance -= Convert.ToDouble(msg2[0]); model.Amount = msg2[0]; db.Entry(ba).State = EntityState.Modified; } catch (Exception ex) { Console.WriteLine("An error occurred: " + ex.Message); } } db.SaveChanges(); } else if (d.Contains("SB A/c") || d.Contains("SBI UPI")) { model.BankName = "SBI"; if (d.Contains("credited ")) { try { model.TransactionType = "Credit"; // resultString = Regex.Match(subjectString, @"\d+").Value; string[] msg1 = msg[1].Split(new string[] { "credited Rs." }, StringSplitOptions.None); string[] msg2 = msg1[1].Split(new string[] { "on" }, StringSplitOptions.None); BankAccounts ba = new BankAccounts(); ba = db.BankAccounts.Where(x => x.BankName.Contains("SBI-H") && x.AccountType == 0).FirstOrDefault(); ba.Balance += Convert.ToDouble(msg2[0]); model.Amount = msg2[0]; db.Entry(ba).State = EntityState.Modified; } catch (Exception ex) { Console.WriteLine("An error occurred: " + ex.Message); } } else if (d.Contains("debited")) { if (msg[1].Contains("INR")) { try { string[] msg1 = msg[1].Split(new string[] { "INR" }, StringSplitOptions.None); string[] msg2 = msg1[1].Split(new string[] { "on" }, StringSplitOptions.None); BankAccounts ba = new BankAccounts(); ba = db.BankAccounts.Where(x => x.BankName.Contains("SBI-H") && x.AccountType == 0).FirstOrDefault(); ba.Balance -= Convert.ToDouble(msg2[0]); model.Amount = msg2[0]; db.Entry(ba).State = EntityState.Modified; } catch (Exception ex) { Console.WriteLine("An error occurred: " + ex.Message); } } else if (msg[1].Contains("is debited for")) { try { model.TransactionType = "Debit"; string[] msg1 = msg[1].Split(new string[] { "is debited for Rs." }, StringSplitOptions.None); string[] msg2 = msg1[1].Split(new string[] { "on" }, StringSplitOptions.None); BankAccounts ba = new BankAccounts(); ba = db.BankAccounts.Where(x => x.BankName.Contains("SBI-H") && x.AccountType == 0).FirstOrDefault(); ba.Balance -= Convert.ToDouble(msg2[0]); model.Amount = msg2[0]; db.Entry(ba).State = EntityState.Modified; } catch (Exception ex) { Console.WriteLine("An error occurred: " + ex.Message); } } } db.SaveChanges(); } //if (db.SMSData.Count() > 0) //{ // DateTime prevDate = db.SMSData.ToList().OrderByDescending(x => x.Date.Value).Select(x => x.Date.Value).First(); // if (model.Date > prevDate) // { db.SMSData.Add(model); } } else { db.SMSData.Add(model); } // Console.WriteLine(i); } // } db.SaveChanges(); } catch (Exception e) { Console.WriteLine("An error occurred: " + e.Message); } return(result); }