Exemplo n.º 1
0
 /// <summary>
 /// Initalizes an instance of the ImapCommand object.
 /// </summary>
 /// <param name="connection">A ImapConnect object representing the connection to use in this instance.</param>
 public ImapCommand(ImapConnect connection)
 {
     this.Connection = connection;
 }
 /// <summary>
 /// Initalizes an instance of the ImapAuthenticate object using the specified connection.
 /// </summary>
 /// <param name="connection">An instance of the ImapConnect object to be used for authentication.</param>
 public ImapAuthenticate(ImapConnect connection)
 {
     Connection = connection;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Saves the new mail attachements to the given path
        /// </summary>
        public void SaveAttachements()
        {
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("tr-TR", false);
            Thread.CurrentThread.CurrentCulture   = new CultureInfo("tr-TR", false);


            if (m_MailMessageFilters.Length == 0)
            {
                throw new Exception("Okunacak mail filtreleri sisteme kaydedilmemiştir.");
            }
            try
            {
                m_Connection          = new ImapConnect();
                m_Connection.Hostname = m_Host;
                m_Connection.Port     = Convert.ToInt32(m_Port);
                m_Connection.Open();
            }
            catch (Exception ex)
            {
                throw new Exception("IMAP Server bağlantısı gerçekleştirilemedi!", ex);
            }
            try
            {
                ImapAuthenticate imapAuthanticate = new ImapAuthenticate(m_Connection, m_UserName, new Crypto().Decrypt(m_Password));

                try
                {
                    imapAuthanticate.Login();
                }
                catch (Exception exd)
                {
                    throw new Exception("Kullanıcı login sırasında hata oluştu. Lütfen kullanıcı adı ve parolayı tekrar gözden geçiriniz.", exd);
                }
                m_ImapMailbox = new ImapMailbox("inbox");
                m_ImapCommand = new ImapCommand(m_Connection);
                m_ImapCommand.Select(m_ImapMailbox.Mailbox);

                ImapMailboxMessage imapMailboxMessage = new ImapMailboxMessage();
                m_ImapCommand.FindUnseenMessageID(m_ImapMailbox);

                foreach (ImapMailboxMessage msg in m_ImapMailbox.Messages)
                {
                    //nevzat: bazen msg.from null geliyor, şimdilik bu mailleri atlayalım
                    if (msg == null || msg.From == null)
                    {
                        /*string d = msg.From + " - " + msg.Received + " - " + msg.HTML + " - " + msg.Errors;
                         * throw new Exception(d);*/
                        continue;
                    }
                    for (int i = 0; i < m_MailMessageFilters.Length; i++)
                    {
                        if ((m_MailMessageFilters[i].From.Equals("") || msg.From.Address.Contains(m_MailMessageFilters[i].From)) &&
                            (m_MailMessageFilters[i].Subject.Equals("") || msg.Subject.Contains(m_MailMessageFilters[i].Subject))
                            )
                        {
                            SavedMails sm = new SavedMails();
                            sm.From = msg.From.Address;
                            m_SavedMails.Add(sm);
                            m_ImapCommand.FetchBodyStructure(msg);
                            int ind = 0;
                            foreach (ImapMessageBodyPart imapMessageBodyPart in msg.BodyParts)
                            {
                                m_ImapCommand.FetchBodyPart(msg, ind);
                                if (imapMessageBodyPart.Attachment && (m_MailMessageFilters[i].FileName.Equals("") || imapMessageBodyPart.FileName.Contains(m_MailMessageFilters[i].FileName)))
                                {
                                    createFile(imapMessageBodyPart, m_MailMessageFilters[i], sm);
                                }
                                ind++;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                m_Connection = null;
                throw ex;
            }
            finally
            {
                if (m_Connection != null && m_Connection.ConnectionState == ConnectionState.Open)
                {
                    m_Connection.Close();
                }
            }
        }
 /// <summary>
 /// Initalizes an instance of the ImapAuthenticate object using the specified connection, username and password.
 /// </summary>
 /// <param name="connection">An instance of the ImapConnect object to be used for authentication.</param>
 /// <param name="username">A string value of the username to use for authentication.</param>
 /// <param name="password">A string value of the password to use for authentication.</param>
 public ImapAuthenticate(ImapConnect connection, string username, string password)
 {
     Connection = connection;
     Username   = username;
     Password   = password;
 }