public void GoogleService_Gmail_GetAttachments() { //arrange string userId = string.Empty; _initSvc.User = userId; //act ListThreadsResponse lThread = _googleSvc.GetThreadList(_initSvc, userId); //assert Thread firstThread = lThread.Threads[0]; if (firstThread.Messages != null) { foreach (Message message in firstThread.Messages) { foreach (MessagePart part in message.Payload.Parts) { if (!string.IsNullOrEmpty(part.Filename)) { string attId = part.Body.AttachmentId; MessagePartBody attachPart = _googleSvc.GetMessageAttachment(_initSvc, userId, message.Id, attId); // Converting from RFC 4648 base64-encoding // see http://en.wikipedia.org/wiki/Base64#Implementations_and_history string attachData = attachPart.Data.Replace('-', '+'); attachData = attachData.Replace('_', '/'); byte[] data = Convert.FromBase64String(attachData); } } } } }
// ... /// <summary> /// List all message threads of 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> private static List <Thread> ListThreads(GmailService service, String userId, int numMessages) { List <Thread> result = new List <Thread>(); UsersResource.ThreadsResource.ListRequest request = service.Users.Threads.List(userId); request.MaxResults = numMessages; request.LabelIds = "INBOX"; ListThreadsResponse response = request.Execute(); result.AddRange(response.Threads); return(result); }
public void GoogleService_Gmail_GetThread() { //arrange string userId = string.Empty; _initSvc.User = userId; //act ListThreadsResponse lThread = _googleSvc.GetThreadList(_initSvc, userId); //assert foreach (Thread thread in lThread.Threads) { Thread t = _googleSvc.GetThread(_initSvc, userId, thread.Id); Assert.IsNotNull(t); } }
public void GoogleService_Gmail_ForwardMessage() { //arrange string userId = string.Empty; string emailTo = string.Empty; _initSvc.User = userId; ListThreadsResponse threadList = _googleSvc.GetThreadList(_initSvc, _initSvc.User); Message message = null; //act foreach (Thread t in threadList.Threads) { message = _googleSvc.ForwardMessage(_initSvc, new EmailMessage() { To = new string[] { emailTo } }, t.Id, _initSvc.User); } //assert Assert.IsNotNull(message); }
public async Task Invalidate() { var fbb = debugger.BeginRequest(); ListThreadsRequest.StartListThreadsRequest(fbb); int requestDataOffset = ListThreadsRequest.EndListThreadsRequest(fbb); var response = await debugger.CommitRequest( fbb, RequestData.ListThreadsRequest, requestDataOffset); ListThreadsResponse responseData = new ListThreadsResponse(); response.GetResponseData(responseData); for (int i = 0; i < responseData.ThreadLength; ++i) { var threadData = responseData.GetThread(i); // threadData.Name; } OnChanged(); }
public List <Thread> ListThreads(GmailService service, String userId) { List <Thread> result = new List <Thread>(); UsersResource.ThreadsResource.ListRequest request = service.Users.Threads.List(userId); do { try { ListThreadsResponse response = request.Execute(); result.AddRange(response.Threads); request.PageToken = response.NextPageToken; } catch (Exception e) { Console.WriteLine("An error occurred: " + e.Message); } } while (!String.IsNullOrEmpty(request.PageToken)); return(result); }
public static Dictionary <Google.Apis.Gmail.v1.Data.Thread, string> GetGmailThreads(string query, int returnAmount) { AuthorizeGmail(); UsersResource.ThreadsResource.ListRequest request = gmailService.Users.Threads.List("me"); request.Q = query; request.MaxResults = returnAmount; ListThreadsResponse response = request.Execute(); List <Google.Apis.Gmail.v1.Data.Thread> threads = response.Threads.ToList(); List <string> threadSubjects = GetThreadSubjects(threads); Dictionary <Google.Apis.Gmail.v1.Data.Thread, string> threadDictionary = new Dictionary <Google.Apis.Gmail.v1.Data.Thread, string>(); for (int i = 0; i < threads.Count; i++) { threadDictionary.Add(threads[i], threadSubjects[i]); } return(threadDictionary); }
public void Configuration(IAppBuilder app) { ConfigureAuth(app); UserCredential credential; using (var stream = new FileStream("client_secret.json", FileMode.Open, FileAccess.Read)) { string credPath = System.Environment.GetFolderPath( System.Environment.SpecialFolder.Personal); credPath = Path.Combine(credPath, ".credentials/gmail-dotnet-quickstart.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 = ApplicationName, }); // Define parameters of request. UsersResource.LabelsResource.ListRequest request = service.Users.Labels.List("me"); // List labels. IList <Label> labels = request.Execute().Labels; Console.WriteLine("Labels:"); if (labels != null && labels.Count > 0) { foreach (var labelItem in labels) { Console.WriteLine("{0}", labelItem.Name); } } else { Console.WriteLine("No labels found."); } // service.Users // request. // Console.Read(); /* * GAlerts alert =new GAlerts("*****@*****.**","qpal1z11"); * alert.create("test", "en", "happens", "all", "best", "feed"); * * foreach(AlertItem item in alert.getList()) * { * * } */ IList <string> urls = new List <string>(); ListThreadsResponse threads = service.Users.Threads.List("me").Execute(); foreach (var thread in threads.Threads.ToList()) { if (thread.Snippet.Contains("Google student success")) { var threadDetails = service.Users.Threads.Get("me", thread.Id).Execute(); var msg = service.Users.Messages.Get("me", threadDetails.Messages[0].Id).Execute(); // byte[] encbuff = Encoding.UTF8.GetBytes(msg.Payload.Parts[0].Body.Data); // string decodedString = HttpServerUtility.UrlTokenEncode(encbuff); // byte[] decbuff = HttpServerUtility.UrlTokenDecode(msg.Payload.Parts[0].Body.Data); // decodedString = Encoding.UTF8.GetString(decbuff); string s = msg.Payload.Parts[0].Body.Data; string incoming = s .Replace('_', '/').Replace('-', '+'); switch (s.Length % 4) { case 2: incoming += "=="; break; case 3: incoming += "="; break; } byte[] bytes = Convert.FromBase64String(incoming); string originalText = Encoding.ASCII.GetString(bytes); var matchCollection = Regex.Matches(originalText, "(http|ftp|https)://([\\w_-]+(?:(?:\\.[\\w_-]+)+))([\\w.,@?^=%&:/~+#-]*[\\w@?^=%&/~+#-])?"); foreach (Match m in matchCollection) { if (!m.Value.Contains("https://www.google.com/alerts")) { urls.Add(m.Value); } } } } }