/// <summary> /// Ведет поиск сообщений для полной докачки данных /// </summary> /// <param name="gRule">Хранит в себе данные о искомых тегах и локальный /// адреса хранения данных на компьютере</param> /// <param name="messages">Список сообщений с ID и Headers</param> /// <returns>Возвращает список id сообщений с которыми совподает теги поиска</returns> public List <string> Find(GRule gRule, List <string> ids) { List <string> listId = new List <string>(); foreach (string id in ids) { var messageData = service.Users.Messages.Get("me", id); messageData.Format = UsersResource.MessagesResource.GetRequest.FormatEnum.Metadata; IList <MessagePartHeader> headers = messageData.Execute().Payload.Headers; foreach (var val in headers) { foreach (GRule item in GRule.grules) { if (val.Value == item.tag) { listId.Add(id); } } } } return(listId); }
static public string Query(GRule gRule) { string result = String.Empty; string type = gRule.type; string mode = gRule.mode; string tags = gRule.tag; if (!String.IsNullOrEmpty(mode)) { switch (mode) { case СONCEPT.MODE.all_messages: return(result); break; case СONCEPT.MODE.label: result += Model.СONCEPT.GetLabel(tags); result += " "; break; case СONCEPT.MODE.subject: result += Model.СONCEPT.GetSubject(tags); result += " "; break; default: break; } } if (!String.IsNullOrEmpty(type)) { result += СONCEPT.GetFilename(type); } return(result); }
public void GetFile(string messageId, ref GRule gRule, Callback callback, Callback progressbar) { byte[] data = null; string filename = ""; var emailRequest = service.Users.Messages.Get("me", messageId); emailRequest.Format = UsersResource.MessagesResource.GetRequest.FormatEnum.Full; var parts = emailRequest.Execute().Payload.Parts; if (parts != null) { foreach (var part in parts) { if (!String.IsNullOrEmpty(part.Filename)) { callback(part.Filename); string[] strs = Regex.Split(part.Filename, "[.]+"); string type = String.Empty; if (String.IsNullOrEmpty(gRule.type)) { type = strs[strs.Length - 1]; } else { type = gRule.type; } if (type == strs[strs.Length - 1]) { ++counterAllFiles; String attId = part.Body.AttachmentId; MessagePartBody attachPart = service.Users.Messages.Attachments.Get("me", messageId, attId).Execute(); String attachData = attachPart.Data.Replace('-', '+'); attachData = attachData.Replace('_', '/'); data = Convert.FromBase64String(attachData); string name = Path.Combine(gRule.path, part.Filename); if (File.Exists(name)) { File.Delete(name); } using (FileStream fileStream = new FileStream(name, FileMode.OpenOrCreate, FileAccess.Write)) { fileStream.Seek(0, SeekOrigin.Begin); int d = data.Length; int offset = 0; for (offset = 0; (data.Length - offset) > 500000; offset += 500000) { int l = data.Length - offset; fileStream.Write(data, offset, 500000); fileStream.Flush(); } fileStream.Write(data, offset, data.Length - offset); fileStream.Close(); } //File.WriteAllBytes(Path.Combine(gRule.path, part.Filename), data); filename = part.Filename; GDownloads gDownloads = new GDownloads(part.Filename, gRule.path, DateTime.Now); Act.FileParser.Add(GDownloads.pathfile, gDownloads); ++downloadFiles; } } } } gRule.lastMesId = messageId; ++processedMessages; progressbar(((processedMessages / allMessages) * 100)); //return filename; }