public object ExecuteEmailRetriever(EbApi Api, Service Service, EbStaticFileClient FileClient, bool isMq) { try { EbConnectionFactory EbConnectionFactory = new EbConnectionFactory(Api.SolutionId, Api.Redis); if (EbConnectionFactory.EmailRetrieveConnection[this.MailConnection] != null) { RetrieverResponse retrieverResponse = EbConnectionFactory.EmailRetrieveConnection[this.MailConnection].Retrieve(Service, this.DefaultSyncDate, FileClient, Api.SolutionId, isMq, SubmitAttachmentAsMultipleForm); EbWebForm _form = Api.Redis.Get <EbWebForm>(this.Reference); SchemaHelper.GetWebFormSchema(_form); if (!(_form is null)) { WebformData data = _form.GetEmptyModel(); foreach (RetrieverMessage _m in retrieverResponse?.RetrieverMessages) { InsertFormData(_form, data, _m, this.Reference, Api.SolutionId, Api.UserObject, Api.Redis, Service, EbConnectionFactory); } } else { throw new ApiException("[ExecuteEmailRetriever], form objects is not in redis."); } } else { throw new ApiException("[ExecuteEmailRetriever], mail connection doesn't exist."); } }
public RetrieverResponse Retrieve(Service service, DateTime DefaultSyncDate, EbStaticFileClient FileClient, string SolnId, bool isMq, bool SubmitAttachmentAsMultipleForm) { RetrieverResponse response = new RetrieverResponse(); using (Pop3Client Client = new Pop3Client(Config.Host, Config.Port, Config.EmailAddress, Config.Password, S22.Pop3.AuthMethod.Login, true)) { try { uint[] u = Client.GetMessageNumbers(); MailMessage[] messages = Client.GetMessages(new uint[] { 1 }, S22.Pop3.FetchOptions.Normal); } catch (S22.Pop3.InvalidCredentialsException) { Console.WriteLine("The server rejected the supplied credentials."); } } return(response); }
public RetrieverResponse Retrieve(Service service, DateTime DefaultSyncDate, EbStaticFileClient FileClient, string SolnId, bool isMq, bool SubmitAttachmentAsMultipleForm) { RetrieverResponse response = new RetrieverResponse(); using (ImapClient Client = new ImapClient(Config.Host, Config.Port, Config.EmailAddress, Config.Password, S22.Imap.AuthMethod.Login, true)) { try { LastSyncedUid = service.Redis.Get <uint>("MailRetrieve_LastsyncedId_" + this.ConId); if (LastSyncedUid == 0)// if value is not in redis { IEnumerable <uint> x = Client.Search(SearchCondition.SentSince(DefaultSyncDate)); uidsCount = x.Count(); if (uidsCount > 0) { LastSyncedUid = x.Min(); } } uidsCount = (uidsCount == 0) ? Client.Search(SearchCondition.GreaterThan(LastSyncedUid)).Where(a => a != MaxUid) .Where(a => a != LastSyncedUid).Count() : uidsCount; if (uidsCount > 0) { MaxUid = LastSyncedUid; for (int i = 0; i <= uidsCount / 50; i++) { IEnumerable <uint> uids = Client.Search(SearchCondition.GreaterThan(MaxUid).And(SearchCondition.LessThan(MaxUid + 51))); MaxUid = uids.Count() > 0 ? uids.Max() : MaxUid; IEnumerable <MailMessage> messages = Client.GetMessages(uids); foreach (MailMessage m in messages) { List <int> _attachments = new List <int>(); List <string> attachment_names = new List <string>();; foreach (System.Net.Mail.Attachment _a in m.Attachments) { int fileId = UploadAttachment(_a, service, SolnId, isMq); _attachments.Add(fileId); if (SubmitAttachmentAsMultipleForm) { response.RetrieverMessages.Add(new RetrieverMessage { Message = m, Attachemnts = _attachments, AttachmentsName = _a.Name }); _attachments = new List <int>(); } else { attachment_names.Add(_a.Name); } } if (!SubmitAttachmentAsMultipleForm || m.Attachments.Count == 0) { response.RetrieverMessages.Add(new RetrieverMessage { Message = m, Attachemnts = _attachments, AttachmentsName = string.Join(',', attachment_names) }); } } } service.Redis.Set("MailRetrieve_LastsyncedId_" + this.ConId, MaxUid); } } catch (S22.Imap.InvalidCredentialsException) { Console.WriteLine("The server rejected the supplied credentials."); } } return(response); }