public void getMailSendImap(string userName, string psw, string service, bool ssl, int port) { try { IMAP_Client imapc = loginMail(userName, psw, service, ssl, port); var folderlist = imapc.GetFolders(null); imapc.SelectFolder("Éléments envoyés"); //imapc.SelectFolder("INBOX"); var folder = imapc.SelectedFolder; var seqSet = IMAP_t_SeqSet.Parse("1:*"); var items = new IMAP_t_Fetch_i[] { new IMAP_t_Fetch_i_Envelope(), new IMAP_t_Fetch_i_Uid(), new IMAP_t_Fetch_i_Flags(), new IMAP_t_Fetch_i_InternalDate(), new IMAP_t_Fetch_i_Rfc822() }; imapc.Fetch(false, seqSet, items, this.m_pImap_Fetch_MessageItems_UntaggedResponse); System.Threading.Thread.Sleep(500); DataTable dtmail = datalistmail.getInstance().getdtSend(); SqlDataAdapter adapteremailrecu = CreerDataAdapterFormail("MailSend"); dtmail.DefaultView.Sort = "maildateTime DESC"; int tr = adapteremailrecu.Update(dtmail.Select(null, null, DataViewRowState.ModifiedCurrent)); int tr12 = adapteremailrecu.Update(dtmail.Select(null, null, DataViewRowState.Added)); //System.Threading.Thread.Sleep(500); imapc.Disconnect(); } catch (Exception ex) { Console.WriteLine("ErrGetMail:" + ex.Message); } }
public void SetDeleted(string TC) { IMAP_t_SeqSet seq = IMAP_t_SeqSet.Parse(_UID + ":" + _UID); Client.StoreMessageFlags(true, seq, IMAP_Flags_SetType.Add, new IMAP_t_MsgFlags(new string[] { IMAP_t_MsgFlags.Deleted })); Client.Expunge(); }
public void supprMailIMAP(string userName, string psw, string service, bool ssl, int port, string mailsupprBegin, string mailsupprEnd) { IMAP_Client imapc = loginMail(userName, psw, service, ssl, port); var folderlist = imapc.GetFolders(null); imapc.SelectFolder("INBOX"); var folder = imapc.SelectedFolder; var seqSet = IMAP_t_SeqSet.Parse("@begin:@end".Replace("@begin", mailsupprBegin).Replace("@end", mailsupprEnd)); var items = new IMAP_t_Fetch_i[] { new IMAP_t_Fetch_i_Envelope(), new IMAP_t_Fetch_i_Uid(), new IMAP_t_Fetch_i_Flags(), new IMAP_t_Fetch_i_InternalDate(), new IMAP_t_Fetch_i_Rfc822() }; try { imapc.StoreMessageFlags(true, seqSet, IMAP_Flags_SetType.Add, new IMAP_t_MsgFlags(new string[] { IMAP_t_MsgFlags.Deleted })); } catch { } imapc.Disconnect(); }
/* * public void marksUnread(IMAP_Client client, IMAP_Client_FetchHandler fetchHandler) * { * IMAP_SequenceSet sequence = new IMAP_SequenceSet(); * //sequence.Parse("*:1"); // from first to last * // the best way to find unread emails is to perform server search * int[] unseen_ids = client.Search(false, "UTF-8", "unseen"); * Console.WriteLine("unseen count: " + unseen_ids.Count().ToString()); * // now we need to initiate our sequence of messages to be fetched * sequence.Parse(string.Join(",", unseen_ids)); * // fetch messages now * client.Fetch(false, sequence, new IMAP_Fetch_DataItem[] { new IMAP_Fetch_DataItem_Envelope() }, fetchHandler); * // uncomment this line to mark messages as read * // client.StoreMessageFlags(false, sequence, IMAP_Flags_SetType.Add, IMAP_MessageFlags.Seen); * * }*/ #region method LoadFolderMessages /// <summary> /// Gets specified folder messages list from IMAP server and adds them to UI. /// </summary> /// <param name="folder">IMAP folder which messages to load.</param> private void LoadFolderMessages(IMAP_Client m_pImap, string folder) { try { m_pImap.SelectFolder(folder); // No messages in folder, skip fetch. if (m_pImap.SelectedFolder.MessagesCount == 0) { return; } // Start fetching. m_pImap.Fetch( false, IMAP_t_SeqSet.Parse("*"), new IMAP_t_Fetch_i[] { new IMAP_t_Fetch_i_Envelope(), new IMAP_t_Fetch_i_Flags(), new IMAP_t_Fetch_i_InternalDate(), new IMAP_t_Fetch_i_Rfc822Size(), new IMAP_t_Fetch_i_Uid() }, m_pImap_Fetch_MessageItems_UntaggedResponse ); } catch (Exception x) { Console.WriteLine(x.ToString()); } }
/// <summary> /// Load specified IMAP message. /// </summary> /// <param name="uid">Message IMAP UID value.</param> private void LoadMessage(long uid) { if (_messages == null) { return; } _curMessage = _messages.First(m => m.UID == uid); if (_curMessage == null) { return; } try { _client.Fetch(true, IMAP_t_SeqSet.Parse(uid.ToString()), new IMAP_t_Fetch_i[] { new IMAP_t_Fetch_i_Rfc822() }, FetchMessageHandler ); } catch (Exception ex) { //Debug.WriteLine(ex.Message); AppJournal.Write("EmailImapTransport: LoadMessage: " + ex.Message); } //savedSeqNo = selMessage.UID; //criteria = SeqSetCriteriaEnum.SaveNo; }
/// <summary> /// Gets specified folder messages list from IMAP server. /// </summary> /// <param name="folder">IMAP folder which messages to load.</param> private void LoadFolder(string folder) { try { _client.SelectFolder(folder); if (_client.SelectedFolder.MessagesCount == 0) { return; } var seqSet = GetSeqSet(); if (seqSet == null) { throw new ArgumentNullException(nameof(seqSet)); } if (string.IsNullOrWhiteSpace(seqSet)) { return; } AppJournal.Write("EmailImapTransport: LoadFolder: Seq_set = " + GetSeqSet()); _client.Fetch(false, IMAP_t_SeqSet.Parse(GetSeqSet()), new IMAP_t_Fetch_i[] { new IMAP_t_Fetch_i_Envelope(), new IMAP_t_Fetch_i_Flags(), new IMAP_t_Fetch_i_InternalDate(), new IMAP_t_Fetch_i_Rfc822Size(), new IMAP_t_Fetch_i_Uid() }, FetchFolderHandler); _savedSeqNo = _messages.Last().UID + 1; _criteria = SeqSetCriteriaEnum.SaveNo; } catch (Exception ex) { //Debug.WriteLine(ex.Message); AppJournal.Write("EmailImapTransport:LoadFolder: " + ex.Message); } }
/// <summary> /// Deletes specified message. /// </summary> /// <param name="uid">Message UID.</param> private void DeleteMessage(long uid) { try { /* NOTE: In IMAP message deleting is 2 step operation. * 1) You need to mark message deleted, by setting "Deleted" flag. * 2) You need to call Expunge command to force server to dele messages physically. */ var sequenceSet = IMAP_t_SeqSet.Parse(uid.ToString()); _client.StoreMessageFlags(true, sequenceSet, IMAP_Flags_SetType.Add, new IMAP_t_MsgFlags(IMAP_t_MsgFlags.Deleted)); _client.Expunge(); } catch (Exception ex) { //Debug.WriteLine(ex.Message); AppJournal.Write("EmailImapTransport: DeleteMessage: " + ex.Message); } }
private void LoadMessage(IMAP_Client m_pImap, string folder) { try {//uid.ToString() m_pImap.SelectFolder(folder); // Start fetching. m_pImap.Fetch( true, IMAP_t_SeqSet.Parse("*"),//последнее письмо должно быть new IMAP_t_Fetch_i[] { new IMAP_t_Fetch_i_Rfc822() }, this.m_pImap_Fetch_Message_UntaggedResponse ); } catch (Exception x) { Console.WriteLine("ЭКСЕПШН" + x.ToString() + "ЗАКОНЧИЛСЯ"); } }
/// <summary> /// Examples: /// 2 -> seq-number (2) /// 2:4 -> seq-range (from 2 - 4) /// 2:* -> seq-range (from 2 to last) /// 2,3,10:* -> sequence-set (seq-number,seq-number,seq-range) /// (2,3, 10 - last) /// </summary> /// <param name="start"></param> /// <param name="end"></param> public void LoadMessages(String start, String end) { Messages.Clear(); if (!_IsConnected) { throw new EMailException { ExceptionType = EMAIL_EXCEPTION_TYPE.NOT_CONNECTED } } ; if (!String.IsNullOrWhiteSpace(_CurrentFolder)) { Client.Fetch( false, IMAP_t_SeqSet.Parse(start + ":" + end), new IMAP_t_Fetch_i[] { new IMAP_t_Fetch_i_Envelope(), new IMAP_t_Fetch_i_Flags(), new IMAP_t_Fetch_i_InternalDate(), new IMAP_t_Fetch_i_Rfc822Size(), new IMAP_t_Fetch_i_Uid() }, (s, e) => { try { IMAP_r_u_Fetch fetchResp = (IMAP_r_u_Fetch)e.Value; string from = ""; if (fetchResp.Envelope.From != null) { for (int i = 0; i < fetchResp.Envelope.From.Length; i++) { // Don't add ; for last item if (i == fetchResp.Envelope.From.Length - 1) { from += fetchResp.Envelope.From[i].ToString(); } else { from += fetchResp.Envelope.From[i].ToString() + ";"; } } } else { from = "<none>"; } string Subject = fetchResp.Envelope.Subject != null ? fetchResp.Envelope.Subject : "<none>"; string Date = fetchResp.InternalDate.Date.ToString("dd.MM.yyyy HH:mm"); string size = ((decimal)(fetchResp.Rfc822Size.Size / (decimal)1000)).ToString("f2") + " kb"; Mail_t_Address[] froms = fetchResp.Envelope.From; string Tag = fetchResp.UID.UID.ToString(); IMAP_Message_Wrapper wr = new IMAP_Message_Wrapper { Client = Client, SequenceNumber = (int)fetchResp.UID.UID, UID = Tag, Date = fetchResp.InternalDate.Date, Size = fetchResp.Rfc822Size.Size, Subject = Subject }; foreach (var item in froms) { if (item is Mail_t_Mailbox) { wr.From.Add(((Mail_t_Mailbox)item).Address); } } //var F = fetchResp.Flags.Flags; //if(!F.Contains("\\Deleted")) _Messages.Add(wr); } catch (Exception exe) { throw new EMailException { ExceptionType = EMAIL_EXCEPTION_TYPE.ERROR_ON_GET_MESSAGE, InnerException = exe }; } } ); if (OnMessagesLoaded != null) { OnMessagesLoaded(this); } } }
public void SetUnrecent() { IMAP_t_SeqSet seq = IMAP_t_SeqSet.Parse(_UID + ":" + _UID); Client.StoreMessageFlags(true, seq, IMAP_Flags_SetType.Remove, new IMAP_t_MsgFlags(new string[] { IMAP_t_MsgFlags.Recent })); }
public void SetAnswered() { IMAP_t_SeqSet seq = IMAP_t_SeqSet.Parse(_UID + ":" + _UID); Client.StoreMessageFlags(true, seq, IMAP_Flags_SetType.Add, new IMAP_t_MsgFlags(new string[] { IMAP_t_MsgFlags.Answered })); }
public void LoadInfos() { if (!Client.IsConnected) { throw new EMailException { ExceptionType = EMAIL_EXCEPTION_TYPE.NOT_CONNECTED } } ; Client.Fetch( true, IMAP_t_SeqSet.Parse(UID), new IMAP_t_Fetch_i[] { new IMAP_t_Fetch_i_Rfc822() }, (sender, e) => { if (e.Value is IMAP_r_u_Fetch) { IMAP_r_u_Fetch fetchResp = (IMAP_r_u_Fetch)e.Value; try { if (fetchResp.Rfc822 != null) { fetchResp.Rfc822.Stream.Position = 0; Mail_Message mime = Mail_Message.ParseFromStream(fetchResp.Rfc822.Stream); fetchResp.Rfc822.Stream.Dispose(); if (String.IsNullOrWhiteSpace(mime.BodyText)) { _TextBody = mime.BodyHtmlText; } else { _TextBody = mime.BodyText; } Attachments.Clear(); foreach (MIME_Entity entity in mime.Attachments) { IMAP_Mail_Attachment att = new IMAP_Mail_Attachment(); if (entity.ContentDisposition != null && entity.ContentDisposition.Param_FileName != null) { att.Text = entity.ContentDisposition.Param_FileName; } else { att.Text = "untitled"; } att.Body = ((MIME_b_SinglepartBase)entity.Body).Data; Attachments.Add(att); } } } catch (Exception exe) { throw new EMailException { ExceptionType = EMAIL_EXCEPTION_TYPE.ERROR_ON_GET_MESSAGE, InnerException = exe }; } } } ); }