Пример #1
0
        void server_AuthUser(object sender, LumiSoft.Net.FTP.Server.AuthUser_EventArgs e)
        {
            e.Validated = false;
            //log("test");

            //throw new NotImplementedException();
        }
Пример #2
0
 private void wOutlookBar_ItemClicked(object sender, LumiSoft.UI.Controls.WOutlookBar.ItemClicked_EventArgs e)
 {
     if (!string.IsNullOrEmpty(e.Item.Tag.ToString().Trim()))
     {
             singleton.m_FrmMain.ShowFunctionFrm(e.Item.Tag.ToString().Trim());
             singleton.m_FrmMain.toolStripStatusLabel3.Text = e.Item.Caption.ToString();
     }
 }
 /// <summary>
 /// Gets requested mime entity data. Returns null if specified mime entity doesn't exist.
 /// </summary>
 /// <param name="parser">Reference to mime parser.</param>
 /// <param name="mimeEntitySpecifier">Mime entity specifier. Nested mime entities are pointed by '.'. 
 /// For example: 1,1.1,2.1, ... .</param>
 /// <returns>Returns requested mime entity data or NULL if requested entry doesn't exist.</returns>
 public static byte[] GetMimeEntityData(LumiSoft.Net.Mime.Mime parser,string mimeEntitySpecifier)
 {
     MimeEntity entity = GetMimeEntity(parser,mimeEntitySpecifier);
     if(entity != null){
         return entity.DataEncoded;
     }
     else{
         return null;
     }
 }
Пример #4
0
        /// <summary>
        /// Gets if specified message matches with this class search-key.
        /// </summary>
        /// <param name="no">IMAP message sequence number.</param>
        /// <param name="uid">IMAP message UID.</param>
        /// <param name="size">IMAP message size in bytes.</param>
        /// <param name="internalDate">IMAP message INTERNALDATE (dateTime when server stored message).</param>
        /// <param name="flags">IMAP message flags.</param>
        /// <param name="mime">Mime message main header only.</param>
        /// <param name="bodyText">Message body text.</param>
        /// <returns></returns>
        public bool Match(long no,long uid,long size,DateTime internalDate,IMAP_MessageFlags flags,LumiSoft.Net.Mime.Mime mime,string bodyText)
        {
            // We must match all keys, if one fails, no need to check others

            foreach(object searckKey in m_pSearchKeys){
                if(!Match_Key_Value(searckKey,no,uid,size,internalDate,flags,mime,bodyText)){
                    return false;
                }
            }

            return true;
        }
        /// <summary>
        /// Gets specified mime entity. Returns null if specified mime entity doesn't exist.
        /// </summary>
        /// <param name="parser">Reference to mime parser.</param>
        /// <param name="mimeEntitySpecifier">Mime entity specifier. Nested mime entities are pointed by '.'. 
        /// For example: 1,1.1,2.1, ... .</param>
        /// <returns></returns>
        public static MimeEntity GetMimeEntity(LumiSoft.Net.Mime.Mime parser,string mimeEntitySpecifier)
        {
            // TODO: nested rfc 822 message

            // For single part message there is only one entity with value 1.
            // Example:
            //		header
            //		entity -> 1

            // For multipart message, entity counting starts from MainEntity.ChildEntities
            // Example:
            //		header
            //		multipart/mixed
            //			entity1  -> 1
            //			entity2  -> 2
            //          ...

            // Single part
            if((parser.MainEntity.ContentType & MediaType_enum.Multipart) == 0){
                if(mimeEntitySpecifier.Length == 1 && Convert.ToInt32(mimeEntitySpecifier) == 1){
                    return parser.MainEntity;
                }
                else{
                    return null;
                }
            }
            // multipart
            else{
                MimeEntity entity = parser.MainEntity;
                string[] parts = mimeEntitySpecifier.Split('.');
                foreach(string part in parts){
                    int mEntryNo = Convert.ToInt32(part) - 1; // Enitites are zero base, mimeEntitySpecifier is 1 based.
                    if(mEntryNo > -1 && mEntryNo < entity.ChildEntities.Count){
                        entity = entity.ChildEntities[mEntryNo];
                    }
                    else{
                        return null;
                    }
                }

                return entity;
            }
        }
Пример #6
0
		public Form1(LumiSoft.UI.Controls.WFrame wFrame)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
			
			PropertyGrid propertyGrid1 = new PropertyGrid();
			propertyGrid1.CommandsVisibleIfAvailable = true;
			propertyGrid1.Location = new Point(5, 25);
			propertyGrid1.Size = new System.Drawing.Size(200, 400);
			propertyGrid1.TabIndex = 1;
			propertyGrid1.Text = "Property Grid";

			this.Controls.Add(propertyGrid1);

			propertyGrid1.SelectedObject = LumiSoft.UI.ViewStyle.staticViewStyle;


			wComboBox1.Items.Add("fsg");
			wComboBox1.Items.Add("gddgddh");
			wComboBox1.Items.Add("fsdshg");
			wComboBox1.Items.Add("wrrurt");
			wComboBox1.Items.Add("iyytii","tag");

			wComboBox2.Items.Add("fsg");
			wComboBox2.Items.Add("gddgddh");
			wComboBox2.Items.Add("fsdshg");
			wComboBox2.Items.Add("wrrurt");
			wComboBox2.Items.Add("iyytii","tag");

			wFrame.Frame_TooBar = this.toolBar1;
		
		}
        private void SMTP_Server_ValidateMailBoxSize(object sender,LumiSoft.Net.SMTP.Server.ValidateMailboxSize_EventArgs e)
        {
            e.IsValid = false;

            try
            {
                string emailAddress = e.eAddress;

                // If domain isn't specified, add default domain
                if(emailAddress.IndexOf("@") == -1){
                    emailAddress += "@" + m_DefaultDomain;
                }

                // If relay or alias address, don't check size
                if(!m_pAPI.DomainExists(emailAddress) || m_pAPI.GetAliasMembers(emailAddress) != null){
                    e.IsValid = true;
                    return;
                }
                //--------------------------------//

                string user = m_pAPI.MapUser(emailAddress);
                if(user == null){
                    string routeMailbox = m_pAPI.GetMailboxFromPattern(emailAddress);

                    // If must route message to remote address, don't check size
                    if(routeMailbox != null){
                        if(routeMailbox.ToUpper().StartsWith("REMOTE:")){
                            e.IsValid = true;
                            return;
                        }
                        else{
                            user = routeMailbox;
                        }
                    }
                }

                if(user != null){
                    e.IsValid = !m_pAPI.ValidateMailboxSize(user);
                }
            }
            catch(Exception x)
            {
                Error.DumpError(x,new System.Diagnostics.StackTrace());
            }
        }
 private void SMTP_Server_SessionLog(object sender,LumiSoft.Net.Log_EventArgs e)
 {
     DateTime today = DateTime.Today;
     string fileName = "smtpCmds_" + today.Year.ToString() + "_" + today.Month.ToString() + "_" + today.Day.ToString() + ".log";
     SCore.WriteLog(m_SMTP_LogPath + fileName,e.LogText);
 }
 private void SMTP_Server_ValidateIPAddress(object sender,LumiSoft.Net.ValidateIP_EventArgs e)
 {
     try
     {
         string IP = Ip_to_longStr(e.ConnectedIP);
         e.Validated = m_pAPI.IsSmtpAccessAllowed(IP);
     }
     catch(Exception x)
     {
         e.Validated = false;
         Error.DumpError(x,new System.Diagnostics.StackTrace());
     }
 }
        /// <summary>
        /// Stores IMAP message flags (\seen,\draft, ...).
        /// </summary>
        /// <param name="mailbox"></param>
        /// <param name="folder"></param>
        /// <param name="message"></param>
        public void StoreMessageFlags(string mailbox,string folder,LumiSoft.Net.IMAP.Server.IMAP_Message message)
        {
            switch(m_DB_Type)
            {
                #region DB_Type.XML

                case DB_Type.XML:
                    string[] fileParts  = message.MessageID.Split('_');
                    string   msgFile    = m_MailStorePath + "Mailboxes\\" + mailbox + "\\" + folder + "\\" + message.MessageID + ".eml";
                    string   msgNewFile = m_MailStorePath + "Mailboxes\\" + mailbox + "\\" + folder + "\\" + fileParts[0] + "_" + fileParts[1] + "_" + Convert.ToString((int)message.Flags) + ".eml";

                    // Check if file exists
                    if(File.Exists(msgFile)){
                        File.Move(msgFile,msgNewFile);

                        // Need to store new messageID(flags changed)
                        message.MessageID = fileParts[0] + "_" + fileParts[1] + "_" + Convert.ToString((int)message.Flags);
                    }
                    break;

                #endregion

                #region DB_Type.MSSQL

                case DB_Type.MSSQL:
                    using(WSqlCommand sqlCmd = new WSqlCommand(m_ConStr,"lspr_StoreMessageFlags")){
                        sqlCmd.AddParameter("@MessageID"    ,SqlDbType.NVarChar,message.MessageID);
                        sqlCmd.AddParameter("@Mailbox"      ,SqlDbType.NVarChar,mailbox);
                        sqlCmd.AddParameter("@Folder"       ,SqlDbType.NVarChar,folder);
                        sqlCmd.AddParameter("@MessageFalgs" ,SqlDbType.Int     ,(int)message.Flags);

                        DataSet ds = sqlCmd.Execute();
                    }
                    break;

                #endregion
            }
        }
 private void smtp_Server_NewMailEvent(object sender,LumiSoft.Net.SMTP.Server.NewMail_EventArgs e)
 {
     try
     {
         ProcessAndStoreMessage(e.MailFrom,e.MailTo,e.MessageStream);
     }
     catch(Exception x){
         Error.DumpError(x,new System.Diagnostics.StackTrace());
         throw new Exception("Error storing message");
     }
 }
 /// <summary>
 /// Constructs FETCH BODY and BODYSTRUCTURE response.
 /// </summary>
 /// <param name="mime">Mime message.</param>
 /// <param name="bodystructure">Specifies if to construct BODY or BODYSTRUCTURE.</param>
 /// <returns></returns>
 public static string ConstructBodyStructure(LumiSoft.Net.Mime.Mime mime,bool bodystructure)
 {
     if(bodystructure){
         return "BODYSTRUCTURE " + ConstructParts(mime.MainEntity,bodystructure);
     }
     else{
         return "BODY " + ConstructParts(mime.MainEntity,bodystructure);
     }
 }
        /// <summary>
        /// Creates copy of message to destination IMAP folder.
        /// </summary>
        /// <param name="accessingUser">User who accesses this method. 
        /// User needs r permission to call this method or Exception is thrown. 
        /// There is special user 'system' for which permission check is skipped.</param>
        /// <param name="folderOwnerUser">User who's folder it is.</param>
        /// <param name="folder">Folder what contains message to copy. For example: Inbox,Public Folders/Documnets .</param>
        /// <param name="destFolderUser">Destination IMAP folder owner user name.</param>
        /// <param name="destFolder">Destination IMAP folder name.</param>
        /// <param name="message">IMAP message which to copy.</param>
        public void CopyMessage(string accessingUser,string folderOwnerUser,string folder,string destFolderUser,string destFolder,LumiSoft.Net.IMAP.Server.IMAP_Message message)
        {
            /* Implementation notes:
                *) Validate values. Throw ArgumnetExcetion if invalid values.
                *) We don't need to map shared folder, check security, it done by GetMessage and StoreMessage methods.
                *) Copy message.
            */

            //--- Validate values -------------------//
            ArgsValidator.ValidateUserName(folderOwnerUser);
            ArgsValidator.ValidateFolder(folder);
            ArgsValidator.ValidateUserName(destFolderUser);
            ArgsValidator.ValidateFolder(destFolder);
            ArgsValidator.ValidateNotNull(message);
            //---------------------------------------//

            //--- Copy message
            //--- Copy message
            EmailMessageItems msgItems = new EmailMessageItems(message.ID,IMAP_MessageItems_enum.Message);
            GetMessageItems(accessingUser,folderOwnerUser,folder,msgItems);
            StoreMessage("system",destFolderUser,destFolder,msgItems.MessageStream,message.InternalDate,message.Flags);
            msgItems.MessageStream.Dispose();
        }
        private void pop3_Server_GetMessage(object sender,LumiSoft.Net.POP3.Server.GetMessage_EventArgs e)
        {
            /* If there is something stored to Tag, this means that message is reomte server message.
             * Message tag structure: pop3Client,messageNr in remote pop3 server.
            */

            try
            {
                string mailbox = e.UserName;
                string msgID = e.MessageID;

                // Local message wanted
                if(e.Message.Tag == null){
                    e.MessageData = MailServer.API.GetMessage(mailbox,"Inbox",msgID);
                }
                // Get remote message
                else{
                    object[] tag = (object[])e.Message.Tag;

                    POP3_Client clnt = (POP3_Client)tag[0];
                    e.MessageData = clnt.GetMessage(Convert.ToInt32(tag[1]));
                }
            }
            catch(Exception x)
            {
                Error.DumpError(x,new System.Diagnostics.StackTrace());
            }
        }
Пример #15
0
        /// <summary>
        /// Checks if specified message matches to specified criteria.
        /// </summary>
        /// <param name="syntaxCheckOnly">Specifies if syntax check is only done. If true no matching is done.</param>
        /// <param name="r">Match expression reader what contains match expression.</param>
        /// <param name="mailFrom">SMTP MAIL FROM: command email value.</param>
        /// <param name="rcptTo">SMTP RCPT TO: command email values.</param>
        /// <param name="smtpSession">SMTP current session.</param>
        /// <param name="mime">Message to match.</param>
        /// <param name="messageSize">Message size in bytes.</param>
        /// <returns>Returns true if message matches to specified criteria.</returns>
        private bool Match(bool syntaxCheckOnly,LumiSoft.Net.StringReader r,string mailFrom,string[] rcptTo,SMTP_Session smtpSession,Mail_Message mime,int messageSize)
        {             
            /* Possible keywords order
                At first there can be NOT,parethesized or matcher
                    After NOT, parethesized or matcher
                    After matcher, AND or OR
                    After OR, NOT,parethesized or matcher
                    After AND, NOT,parethesized or matcher
                    After parethesized, NOT or matcher
            */
 
            PossibleClauseItem possibleClauseItems = PossibleClauseItem.Parenthesizes | PossibleClauseItem.NOT | PossibleClauseItem.Matcher;
            bool lastMatchValue = false;

            // Empty string passed 
            r.ReadToFirstChar();
            if(r.Available == 0){
                throw new Exception("Invalid syntax: '" + ClauseItemsToString(possibleClauseItems) + "' expected !");
            }

            // Parse while there are expressions or get error
            while(r.Available > 0){
                r.ReadToFirstChar();

                // Syntax check must consider that there is alwas match !!!
                if(syntaxCheckOnly){
                    lastMatchValue = true;
                }

                #region () Groupped matchers

                // () Groupped matchers
                if(r.StartsWith("(")){
                    lastMatchValue = Match(syntaxCheckOnly,new LumiSoft.Net.StringReader(r.ReadParenthesized()),mailFrom,rcptTo,smtpSession,mime,messageSize);

                    possibleClauseItems = PossibleClauseItem.Parenthesizes | PossibleClauseItem.Matcher | PossibleClauseItem.NOT;
                }

                #endregion

                #region AND clause

                // AND clause
                else if(r.StartsWith("and",false)){
                    // See if AND allowed
                    if((possibleClauseItems & PossibleClauseItem.AND) == 0){
                        throw new Exception("Invalid syntax: '" + ClauseItemsToString(possibleClauseItems) + "' expected !");
                    }
                    
                    // Last match value is false, no need to check next conditions
                    if(!lastMatchValue){
                        return false;
                    }

                    // Remove AND
                    r.ReadWord();
                    r.ReadToFirstChar();

                    lastMatchValue = Match(syntaxCheckOnly,r,mailFrom,rcptTo,smtpSession,mime,messageSize);

                    possibleClauseItems = PossibleClauseItem.Parenthesizes | PossibleClauseItem.Matcher | PossibleClauseItem.NOT;
                }

                #endregion

                #region OR clause

                // OR clause
                else if(r.StartsWith("or",false)){
                    // See if OR allowed
                    if((possibleClauseItems & PossibleClauseItem.OR) == 0){
                        throw new Exception("Invalid syntax: '" + ClauseItemsToString(possibleClauseItems) + "' expected !");
                    }

                    // Remove OR
                    r.ReadWord();
                    r.ReadToFirstChar();

                    // Last match value is false, then we need to check next condition.
                    // Otherwise OR is matched already, just eat next matcher.
                    if(lastMatchValue){
                        // Skip next clause
                        Match(syntaxCheckOnly,r,mailFrom,rcptTo,smtpSession,mime,messageSize);
                    }
                    else{
                        lastMatchValue = Match(syntaxCheckOnly,r,mailFrom,rcptTo,smtpSession,mime,messageSize);
                    }

                    possibleClauseItems = PossibleClauseItem.Parenthesizes | PossibleClauseItem.Matcher | PossibleClauseItem.NOT;
                }

                #endregion

                #region NOT clause

                // NOT clause
                else if(r.StartsWith("not",false)){
                    // See if NOT allowed
                    if((possibleClauseItems & PossibleClauseItem.NOT) == 0){
                        throw new Exception("Invalid syntax: '" + ClauseItemsToString(possibleClauseItems) + "' expected !");
                    }

                    // Remove NOT
                    r.ReadWord();
                    r.ReadToFirstChar();

                    // Just reverse match result value
                    lastMatchValue = !Match(syntaxCheckOnly,r,mailFrom,rcptTo,smtpSession,mime,messageSize);

                    possibleClauseItems = PossibleClauseItem.Parenthesizes | PossibleClauseItem.Matcher;
                }

                #endregion

                else{
                    // See if matcher allowed
                    if((possibleClauseItems & PossibleClauseItem.Matcher) == 0){
                        throw new Exception("Invalid syntax: '" + ClauseItemsToString(possibleClauseItems) + "' expected ! \r\n\r\n Near: '" + r.OriginalString.Substring(0,r.Position) + "'");
                    }

                    // 1) matchsource
                    // 2) keyword
                
                    // Read match source
                    string word = r.ReadWord();
                    if(word == null){
                        throw new Exception("Invalid syntax: matcher is missing !");
                    }
                    word = word.ToLower();
                    string[] matchSourceValues = new string[]{};


                    #region smtp.mail_from
                    
                    // SMTP command MAIL FROM: value.
                    //  smtp.mail_from
                    if(word == "smtp.mail_from"){
                        if(!syntaxCheckOnly){
                            matchSourceValues = new string[]{mailFrom};
                        }
                    }

                    #endregion

                    #region smtp.rcpt_to

                    // SMTP command RCPT TO: values.
                    //  smtp.mail_to
                    else if(word == "smtp.rcpt_to"){
                        if(!syntaxCheckOnly){
                            matchSourceValues = rcptTo;
                        }
                    }

                    #endregion

                    #region smtp.ehlo

                    // SMTP command EHLO/HELO: value.
                    //  smtp.ehlo
                    else if(word == "smtp.ehlo"){
                        if(!syntaxCheckOnly){
                            matchSourceValues = new string[]{smtpSession.EhloHost};
                        }
                    }

                    #endregion

                    #region smtp.authenticated

                    // Specifies if SMTP session is authenticated.
                    //  smtp.authenticated
                    else if(word == "smtp.authenticated"){
                        if(!syntaxCheckOnly){
                            if(smtpSession != null){
                                matchSourceValues = new string[]{smtpSession.IsAuthenticated.ToString()};
                            }
                        }
                    }

                    #endregion

                    #region smtp.user

                    // SMTP authenticated user name. Empy string "" if not authenticated.
                    //  smtp.user
                    else if(word == "smtp.user"){
                        if(!syntaxCheckOnly){
                            if(smtpSession != null && smtpSession.AuthenticatedUserIdentity != null){
                                matchSourceValues = new string[]{smtpSession.AuthenticatedUserIdentity.Name};
                            }
                        }
                    }

                    #endregion

                    #region smtp.remote_ip

                    // SMTP session connected client IP address.
                    //  smtp.remote_ip
                    else if(word == "smtp.remote_ip"){
                        if(!syntaxCheckOnly){
                            if(smtpSession != null){
                                matchSourceValues = new string[]{smtpSession.RemoteEndPoint.Address.ToString()};
                            }
                        }
                    }

                    #endregion

                    
                    #region message.size

                    // Message size in bytes.
                    //  message.size
                    else if(word == "message.size"){
                        if(!syntaxCheckOnly){
                            matchSourceValues = new string[]{messageSize.ToString()};
                        }
                    }

                    #endregion

                    #region message.header <SP> "HeaderFieldName:"

                    // Message main header header field. If multiple header fields, then all are checked.
                    //  message.header <SP> "HeaderFieldName:"
                    else if(word == "message.header"){
                        string headerFieldName = r.ReadWord();
                        if(headerFieldName == null){
                            throw new Exception("Match source MainHeaderField HeaderFieldName is missing ! Syntax:{MainHeaderField <SP> \"HeaderFieldName:\"}");
                        }
                    
                        if(!syntaxCheckOnly){
                            if(mime.Header.Contains(headerFieldName)){
                                MIME_h[] fields = mime.Header[headerFieldName];
                                matchSourceValues = new string[fields.Length];
                                for(int i=0;i<matchSourceValues.Length;i++){
                                    matchSourceValues[i] = fields[i].ValueToString();
                                }
                            }
                        }
                    }

                    #endregion

                    #region message.all_headers <SP> "HeaderFieldName:"

                    // Any mime entity header header field. If multiple header fields, then all are checked.
                    //  message.all_headers <SP> "HeaderFieldName:"
                    else if(word == "message.all_headers"){
                        string headerFieldName = r.ReadWord();
                        if(headerFieldName == null){
                            throw new Exception("Match source MainHeaderField HeaderFieldName is missing ! Syntax:{MainHeaderField <SP> \"HeaderFieldName:\"}");
                        }

                        if(!syntaxCheckOnly){
                            List<string> values = new List<string>();
                            foreach(MIME_Entity entity in mime.AllEntities){
                                if(entity.Header.Contains(headerFieldName)){
                                    MIME_h[] fields = entity.Header[headerFieldName];
                                    for(int i=0;i<fields.Length;i++){
                                        values.Add(fields[i].ValueToString());
                                    }
                                }
                            }
                            matchSourceValues = values.ToArray();
                        }
                    }

                    #endregion

                    #region message.body_text

                    // Message body text.
                    //  message.body_text
                    else if(word == "message.body_text"){
                        if(!syntaxCheckOnly){
                            matchSourceValues = new string[]{mime.BodyText};
                        }
                    }

                    #endregion

                    #region message.body_html

                    // Message body html.
                    //  message.body_html
                    else if(word == "message.body_html"){
                        if(!syntaxCheckOnly){
                            matchSourceValues = new string[]{mime.BodyHtmlText};
                        }
                    }

                    #endregion

                    #region message.content_md5

                    // Message any mime entity decoded data MD5 hash.
                    //  message.content_md5
                    else if(word == "message.content_md5"){
                        if(!syntaxCheckOnly){
                            List<string> values = new List<string>();
                            foreach(MIME_Entity entity in mime.AllEntities){
                                try{
                                    if(entity.Body is MIME_b_SinglepartBase){
                                        byte[] data = ((MIME_b_SinglepartBase)entity.Body).Data;
                                        if(data != null){
                                            System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
                                            values.Add(System.Text.Encoding.Default.GetString(md5.ComputeHash(data)));
                                        }
                                    }
                                }
                                catch{
                                    // Message data parsing failed, just skip that entity md5
                                }
                            }
                            matchSourceValues = values.ToArray();
                        }
                    }

                    #endregion


                    #region sys.date_time

                    // System current date time. Format: yyyy.MM.dd HH:mm:ss.
                    //  sys.date_time
                    else if(word == "sys.date_time"){
                        if(!syntaxCheckOnly){
                            matchSourceValues = new string[]{DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss")};
                        }
                    }

                    #endregion

                    #region sys.date

                    // System current date. Format: yyyy.MM.dd.
                    //  sys.date
                    else if(word == "sys.date"){
                        if(!syntaxCheckOnly){
                            matchSourceValues = new string[]{DateTime.Today.ToString("dd.MM.yyyy")};
                        }
                    }

                    #endregion

                    #region sys.time

                    // System current time. Format: HH:mm:ss.
                    //  sys.time
                    else if(word == "sys.time"){
                        if(!syntaxCheckOnly){
                            matchSourceValues = new string[]{DateTime.Now.ToString("HH:mm:ss")};
                        }
                    }

                    #endregion

                    #region sys.day_of_week

                    // Day of week. Days: sunday,monday,tuesday,wednesday,thursday,friday,saturday.
                    //  sys.day_of_week
                    else if(word == "sys.day_of_week"){
                        if(!syntaxCheckOnly){
                            matchSourceValues = new string[]{DateTime.Today.DayOfWeek.ToString()};
                        }
                    }

                    #endregion

                    /*
                    // Day of month. Format: 1 - 31. If no so much days in month, then replaced with month max days.
                    // sys.day_of_month
                    else if(word == "sys.day_of_month"){
                    }
*/
                    #region sys.day_of_year

                    // Month of year. Format: 1 - 12.
                    // sys.day_of_year
                    else if(word == "sys.day_of_year"){
                        if(!syntaxCheckOnly){
                            matchSourceValues = new string[]{DateTime.Today.ToString("M")};
                        }
                    }

                    #endregion

                    #region Unknown

                    // Unknown
                    else{
                        throw new Exception("Unknown match source '" + word + "' !");
                    }

                    #endregion

                    
                    /* If we reach so far, then we have valid match sorce and compare value.
                       Just do compare.
                    */

                    // Reset lastMatch result
                    lastMatchValue = false;

                    // Read matcher
                    word = r.ReadWord(true,new char[]{' '},true);
                    if(word == null){
                        throw new Exception("Invalid syntax: operator is missing ! \r\n\r\n Near: '" + r.OriginalString.Substring(0,r.Position) + "'");
                    }
                    word = word.ToLower();

                    #region * <SP> "astericPattern"

                    // * <SP> "astericPattern"
                    if(word == "*"){
                        string val = r.ReadWord();
                        if(val == null){
                            throw new Exception("Invalid syntax: <SP> \"value\" is missing !");
                        }
                        val = val.ToLower();
                        
                        if(!syntaxCheckOnly){
                            // We check matchSourceValues when first is found 
                            foreach(string matchSourceValue in matchSourceValues){                            
                                if(SCore.IsAstericMatch(val,matchSourceValue.ToLower())){
                                    lastMatchValue = true;
                                    break;
                                }
                            }
                        }
                    }

                    #endregion

                    #region !* <SP> "astericPattern"

                    // !* <SP> "astericPattern"
                    else if(word == "!*"){
                        string val = r.ReadWord();
                        if(val == null){
                            throw new Exception("Invalid syntax: <SP> \"value\" is missing !");
                        }
                        val = val.ToLower();
                        
                        if(!syntaxCheckOnly){
                            // We check matchSourceValues when first is found 
                            foreach(string matchSourceValue in matchSourceValues){                            
                                if(SCore.IsAstericMatch(val,matchSourceValue.ToLower())){
                                    lastMatchValue = false;
                                    break;
                                }
                            }
                        }
                    }

                    #endregion

                    #region == <SP> "value"

                    // == <SP> "value"
                    else if(word == "=="){
                        string val = r.ReadWord();
                        if(val == null){
                            throw new Exception("Invalid syntax: <SP> \"value\" is missing !");
                        }
                        val = val.ToLower();

                        if(!syntaxCheckOnly){
                            // We check matchSourceValues when first is found 
                            foreach(string matchSourceValue in matchSourceValues){
                                if(val == matchSourceValue.ToLower()){
                                    lastMatchValue = true;
                                    break;
                                }
                            }
                        }
                    }

                    #endregion

                    #region != <SP> "value"

                    // != <SP> "value"
                    else if(word == "!="){
                        string val = r.ReadWord();
                        if(val == null){
                            throw new Exception("Invalid syntax: <SP> \"value\" is missing !");
                        }
                        val = val.ToLower();

                        if(!syntaxCheckOnly){
                            // We check matchSourceValues when first is found, then already value equals 
                            foreach(string matchSourceValue in matchSourceValues){
                                if(val == matchSourceValue.ToLower()){
                                    lastMatchValue = false;
                                    break;
                                }
                                lastMatchValue = true;
                            }
                        }
                    }

                    #endregion

                    #region >= <SP> "value"

                    // >= <SP> "value"
                    else if(word == ">="){
                        string val = r.ReadWord();
                        if(val == null){
                            throw new Exception("Invalid syntax: <SP> \"value\" is missing !");
                        }
                        val = val.ToLower();

                        if(!syntaxCheckOnly){
                            // We check matchSourceValues when first is found 
                            foreach(string matchSourceValue in matchSourceValues){
                                if(matchSourceValue.ToLower().CompareTo(val) >= 0){
                                    lastMatchValue = true;
                                    break;
                                }
                            }
                        }
                    }

                    #endregion

                    #region <= <SP> "value"

                    // <= <SP> "value"
                    else if(word == "<="){
                        string val = r.ReadWord();
                        if(val == null){
                            throw new Exception("Invalid syntax: <SP> \"value\" is missing !");
                        }
                        val = val.ToLower();

                        if(!syntaxCheckOnly){
                            // We check matchSourceValues when first is found 
                            foreach(string matchSourceValue in matchSourceValues){
                                if(matchSourceValue.ToLower().CompareTo(val) <= 0){
                                    lastMatchValue = true;
                                    break;
                                }
                            }
                        }
                    }

                    #endregion

                    #region > <SP> "value"

                    // > <SP> "value"
                    else if(word == ">"){
                        string val = r.ReadWord();
                        if(val == null){
                            throw new Exception("Invalid syntax: <SP> \"value\" is missing !");
                        }
                        val = val.ToLower();

                        if(!syntaxCheckOnly){
                            // We check matchSourceValues when first is found 
                            foreach(string matchSourceValue in matchSourceValues){
                                if(matchSourceValue.ToLower().CompareTo(val) > 0){
                                    lastMatchValue = true;
                                    break;
                                }
                            }
                        }
                    }

                    #endregion

                    #region < <SP> "value"

                    // < <SP> "value"
                    else if(word == "<"){
                        string val = r.ReadWord();
                        if(val == null){
                            throw new Exception("Invalid syntax: <SP> \"value\" is missing !");
                        }
                        val = val.ToLower();

                        if(!syntaxCheckOnly){
                            // We check matchSourceValues when first is found 
                            foreach(string matchSourceValue in matchSourceValues){
                                if(matchSourceValue.ToLower().CompareTo(val) < 0){
                                    lastMatchValue = true;
                                    break;
                                }
                            }
                        }
                    }

                    #endregion

                    #region regex <SP> "value"

                    // Regex <SP> "value"
                    else if(word == "regex"){
                        string val = r.ReadWord();
                        if(val == null){
                            throw new Exception("Invalid syntax: <SP> \"value\" is missing !");
                        }
                        val = val.ToLower();

                        if(!syntaxCheckOnly){
                            // We check matchSourceValues when first is found 
                            foreach(string matchSourceValue in matchSourceValues){                            
                                if(Regex.IsMatch(val,matchSourceValue.ToLower())){
                                    lastMatchValue = true;
                                    break;
                                }
                            }
                        }
                    }

                    #endregion

                    #region Unknown

                    // Unknown
                    else{
                        throw new Exception("Unknown keword '" + word + "' !");
                    }

                    #endregion

                    possibleClauseItems = PossibleClauseItem.AND | PossibleClauseItem.OR;
                }
            }

            return lastMatchValue;
        }
 private void OnServer_SysError(object sender,LumiSoft.Net.Error_EventArgs e)
 {
     Error.DumpError(e.Exception,e.StackTrace);
 }
        private void pop3_Server_DeleteMessage(object sender,LumiSoft.Net.POP3.Server.DeleteMessage_EventArgs e)
        {
            /* If there is something stored to Tag, this means that message is reomte server message.
             * Message tag structure: pop3Client,messageNr in remote pop3 server.
            */

            try
            {
                if(e.Message.Tag == null){
                    MailServer.API.DeleteMessage(e.UserName,"Inbox",e.MessageID);
                }
                // Delete remote message
                else{
                    object[] tag = (object[])e.Message.Tag;

                    POP3_Client clnt = (POP3_Client)tag[0];
                    clnt.DeleteMessage(Convert.ToInt32(tag[1]));
                }
            }
            catch(Exception x)
            {
                Error.DumpError(x,new System.Diagnostics.StackTrace());
            }
        }
 private void smtp_Server_ValidateSender(object sender,LumiSoft.Net.SMTP.Server.ValidateSender_EventArgs e)
 {
     e.Validated = true;
 }
        private void smtp_Server_ValidateRecipient(object sender,LumiSoft.Net.SMTP.Server.ValidateRecipient_EventArgs e)
        {
            try
            {
                e.Validated = false;

                string mailTo = e.MailTo;

                // If domain isn't specified, add default domain
                if(mailTo.IndexOf("@") == -1){
                    mailTo += "@" + m_DefaultDomain;
                }

                //1) is local domain or relay needed
                //2) can map email address to mailbox
                //3) is alias
                //4) if matches any routing pattern

                // check if e-domain is local
                if(m_pAPI.DomainExists(mailTo)){
                    if(m_pAPI.MapUser(mailTo) == null){
                        // Check if alias.
                        if(m_pAPI.GetAliasMembers(mailTo) != null){
                            // Always allow authenticated users to use aliases
                            if(e.Authenticated){
                                e.Validated = true;
                            }
                            // For not authenticated users, allow to use only public aliases
                            else if(m_pAPI.IsAliasPublic(mailTo)){
                                e.Validated = true;
                            }
                        }
                        // At least check if matches any routing pattern.
                        else if(m_pAPI.GetMailboxFromPattern(mailTo) != null){
                            e.Validated = true;
                        }
                    }
                    else{
                        e.Validated = true;
                    }
                }
                // Not this server recipient
                else{
                    e.LocalRecipient = false;

                    // This isn't domain what we want.
                    // 1)If user Authenticated, check if relay is allowed for this user.
                    // 2)Check if relay is allowed for this ip.
                    if(e.Authenticated){
                        if(m_pAPI.IsRelayAllowedUser(e.Session.UserName)){
                            e.Validated = true;
                        }
                    }
                    else if(m_pAPI.IsRelayAllowedIP(Ip_to_longStr(e.ConnectedIP))){
                        e.Validated = true;
                    }
                }
            }
            catch(Exception x)
            {
                Error.DumpError(x,new System.Diagnostics.StackTrace());
            }
        }
        /// <summary>
        /// Creates copy of message to destination folder.
        /// </summary>
        /// <param name="mailbox">MailBox name.</param>
        /// <param name="folder"></param>
        /// <param name="destFolder"></param>
        /// <param name="message"></param>
        public void CopyMessage(string mailbox,string folder,string destFolder,LumiSoft.Net.IMAP.Server.IMAP_Message message)
        {
            switch(m_DB_Type)
            {
                #region DB_Type.XML

                case DB_Type.XML:
                    string msgFile = m_MailStorePath + "Mailboxes\\" + mailbox + "\\" + folder + "\\" + message.MessageID + ".eml";

                    // Check if file exists
                    if(!File.Exists(msgFile)){
                        throw new Exception("Message doesn't exist");
                    }

                    // Check if dest folder exists
                    if(!Directory.Exists(m_MailStorePath + "Mailboxes\\" + mailbox + "\\" + destFolder)){
                        throw new Exception("Destination folder doesn't exist");
                    }

                    // We need to change UID of message to maximum of dest folder UID.
                    int newUID = GetNextUid(mailbox,destFolder);
                    string[] fileParts = message.MessageID.Split('_');
                    string msgFileDest = m_MailStorePath + "Mailboxes\\" + mailbox + "\\" + destFolder + "\\" + fileParts[0] + "_" + newUID + "_" + Convert.ToString((int)message.Flags) + ".eml";

                    File.Copy(msgFile,msgFileDest);

                    break;

                #endregion

                #region DB_Type.MSSQL

                case DB_Type.MSSQL:
                    using(WSqlCommand sqlCmd = new WSqlCommand(m_ConStr,"lspr_CopyMessage")){
                        sqlCmd.AddParameter("@MessageID"  ,SqlDbType.NVarChar,message.MessageID);
                        sqlCmd.AddParameter("@Mailbox"    ,SqlDbType.NVarChar,mailbox);
                        sqlCmd.AddParameter("@Folder"     ,SqlDbType.NVarChar,folder);
                        sqlCmd.AddParameter("@DestFolder" ,SqlDbType.NVarChar,destFolder);

                        DataSet ds = sqlCmd.Execute();
                    }
                    break;

                #endregion
            }
        }
 /// <summary>
 /// Gets requested mime entity header. Returns null if specified mime entity doesn't exist.
 /// Note: Header terminator blank line is included.
 /// </summary>
 /// <param name="parser">Reference to mime parser.</param>
 /// <param name="mimeEntitySpecifier">Mime entity specifier. Nested mime entities are pointed by '.'. 
 /// For example: 1,1.1,2.1, ... .</param>
 /// <returns>Returns requested mime entity data or NULL if requested entry doesn't exist.</returns>
 public static byte[] GetMimeEntityHeader(LumiSoft.Net.Mime.Mime parser,string mimeEntitySpecifier)
 {
     MimeEntity mEntry = GetMimeEntity(parser,mimeEntitySpecifier);
     if(mEntry != null){
         return GetMimeEntityHeader(mEntry);
     }
     else{
         return null;
     }
 }
        /// <summary>
        /// Gets Inbox messages info for specified user mailbox.
        /// </summary>
        /// <param name="mailBox"></param>
        /// <param name="msgs"></param>
        public void GetMessageList(string mailBox,LumiSoft.Net.POP3.Server.POP3_Messages msgs)
        {
            switch(m_DB_Type)
            {
                #region DB_Type.XML

                case DB_Type.XML:
                    string path = m_MailStorePath + "Mailboxes\\" + mailBox + "\\Inbox\\";

                    // Check if Directory exists, if not Create
                    if(!Directory.Exists(path)){
                        Directory.CreateDirectory(path);
                    }

                    string[] files = Directory.GetFiles(path,"*.eml");

                    foreach(string file in files){
                        int messageSize = 0;
                        using(FileStream fStream = File.OpenRead(file)){
                            messageSize = (int)fStream.Length;
                        }

                        msgs.AddMessage(Path.GetFileNameWithoutExtension(file),messageSize);
                    }
                    break;

                #endregion

                #region DB_Type.MSSQL

                case DB_Type.MSSQL:
                    using(WSqlCommand sqlCmd = new WSqlCommand(m_ConStr,"lspr_GetMessageList")){
                        sqlCmd.AddParameter("@Mailbox",SqlDbType.NVarChar,mailBox);
                        sqlCmd.AddParameter("@Folder" ,SqlDbType.NVarChar,"Inbox");

                        DataSet ds = sqlCmd.Execute();
                        ds.Tables[0].TableName = "lsMailStore";

                        foreach(DataRow dr in ds.Tables["lsMailStore"].Rows){
                            string messageID = dr["MessageID"].ToString();
                            int    size      = Convert.ToInt32(dr["Size"]);
                            msgs.AddMessage(messageID,size);
                        }
                    }
                    break;

                #endregion
            }
        }
Пример #23
0
        /// <summary>
        /// Is called when RTP session gets unhandled error.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">Event data.</param>
        private void m_pSession_Error(object sender,LumiSoft.Net.ExceptionEventArgs e)
        {
            if(m_IsDisposed){
                return;
            }

            // Move processing to UI thread.
            this.BeginInvoke(new MethodInvoker(delegate(){
                ListViewItem item = new ListViewItem(e.Exception.Message);
                item.Tag = e.Exception;
                m_pErrors.Items.Add(item);
            }));
        }
 private void Server_AuthenticateUser(object sender,LumiSoft.Net.SMTP.Server.AuthUser_EventArgs e)
 {
     try
     {
         e.Validated = m_pAPI.AuthUser(e.UserName,e.PasswData,e.AuthData,e.AuthType);
     }
     catch(Exception x)
     {
         e.Validated = false;
         Error.DumpError(x,new System.Diagnostics.StackTrace());
     }
 }
        /// <summary>
        /// Stores IMAP message flags (\seen,\draft, ...).
        /// </summary>
        /// <param name="accessingUser">User who accesses this method. 
        /// User needs r permission to call this method or Exception is thrown. 
        /// There is special user 'system' for which permission check is skipped.</param>
        /// <param name="folderOwnerUser">User who's folder it is.</param>
        /// <param name="folder">Folder which message flags to store. For example: Inbox,Public Folders/Documnets .</param>
        /// <param name="message">Fix ME: ???</param>
        /// <param name="msgFlags">Message flags to store.</param>
        public void StoreMessageFlags(string accessingUser,string folderOwnerUser,string folder,LumiSoft.Net.IMAP.Server.IMAP_Message message,IMAP_MessageFlags msgFlags)
        {
            /* Implementation notes:
                *) Validate values. Throw ArgumnetExcetion if invalid values.
                *) Ensure that user exists.
                *) Normalize folder. Remove '/' from folder start and end, ... .
                *) Do Shared Folders mapping.
                *) Ensure that folder exists. Throw Exception if don't.
                *) Remove all message flags which permissions user doesn't have.
                *) Store message.
            */

            //--- Validate values -------------------//
            ArgsValidator.ValidateUserName(folderOwnerUser);
            ArgsValidator.ValidateFolder(folder);
            ArgsValidator.ValidateNotNull(message);
            //---------------------------------------//

            // Ensure that user exists.
            if(!UserExists(folderOwnerUser)){
                throw new Exception("User '" + folderOwnerUser + "' doesn't exist !");
            }

            // Normalize folder. Remove '/' from folder start and end.
            folder = API_Utlis.NormalizeFolder(folder);

            // Do Shared Folders mapping.
            string originalFolder = folder;
            SharedFolderMapInfo mappedFolder = MapSharedFolder(originalFolder);
            if(mappedFolder.IsSharedFolder){
                folderOwnerUser = mappedFolder.FolderOnwer;
                folder = mappedFolder.Folder;

                if(folderOwnerUser == "" || folder == ""){
                    throw new ArgumentException("Specified root folder '" + originalFolder + "' isn't accessible !");
                }
            }

            // Ensure that folder exists. Throw Exception if don't.
            if(!FolderExists(folderOwnerUser + "/" + folder)){
                throw new Exception("Folder '" + folder + "' doesn't exist !");
            }

            // Remove all message flags which permissions user doesn't have.
            if(accessingUser != "system"){
                IMAP_ACL_Flags userACL = GetUserACL(folderOwnerUser,folder,accessingUser);
                if((userACL & IMAP_ACL_Flags.s) == 0){
                    msgFlags &= ~IMAP_MessageFlags.Seen;
                }
                else if((userACL & IMAP_ACL_Flags.d) == 0){
                    msgFlags &= ~IMAP_MessageFlags.Deleted;
                }
                else if((userACL & IMAP_ACL_Flags.s) == 0){
                    msgFlags &= (~IMAP_MessageFlags.Answered | ~IMAP_MessageFlags.Draft | ~IMAP_MessageFlags.Flagged);
                }
            }

            //--- Store message flags
            using(WSqlCommand sqlCmd = new WSqlCommand(m_ConStr,"lspr_StoreMessageFlags")){
                sqlCmd.AddParameter("_userName"     ,NpgsqlDbType.Varchar,folderOwnerUser);
                sqlCmd.AddParameter("_folder"       ,NpgsqlDbType.Varchar,folder);
                sqlCmd.AddParameter("_messageID"    ,NpgsqlDbType.Varchar,message.ID);
                sqlCmd.AddParameter("_messageFlags" ,NpgsqlDbType.Integer,(int)message.Flags);

                DataSet ds = sqlCmd.Execute();
            }
        }
        private void Server_AuthenticateUser(object sender,LumiSoft.Net.POP3.Server.AuthUser_EventArgs e)
        {
            try
            {
                e.Validated = m_pAPI.AuthUser(e.UserName,e.PasswData,e.AuthData,e.AuthType);
                if(e.Validated == false){
                    return;
                }

                //----- Remote pop3 servers ---------------------------------------//
                DataSet ds = m_pAPI.GetUserRemotePop3Servers(e.UserName);

                // Connect to external pop3 servers
                ArrayList extrnPop3Servers = new ArrayList();
                foreach(DataRow dr in ds.Tables["RemotePop3Servers"].Rows){
                    try
                    {
                        string server = dr["Server"].ToString();
                        int    port   = Convert.ToInt32(dr["Port"]);
                        string user   = dr["UserName"].ToString();
                        string passw  = dr["Password"].ToString();

                        POP3_Client clnt = new POP3_Client();
                        clnt.Connect(server,port);
                        clnt.Authenticate(user,passw,false);

                        extrnPop3Servers.Add(clnt);
                    }
                    catch(Exception x){
                    }
                }

                if(extrnPop3Servers.Count > 0){
                    e.Session.Tag = extrnPop3Servers;
                }
                //---------------------------------------------------------------------//
            }
            catch(Exception x)
            {
                e.Validated = false;
                Error.DumpError(x,new System.Diagnostics.StackTrace());
            }
        }
        private void pop3_Server_GetMessgesList(object sender,LumiSoft.Net.POP3.Server.GetMessagesInfo_EventArgs e)
        {
            try
            {
                string userName = e.UserName;

                MailServer.API.GetMessageList(userName,e.Messages);

                //--------- Remote pop3 server -----------------------------------------------------------------------//
                // Get external pop3 server messages list, append it to local list.
                if(e.Session.Tag != null){
                    ArrayList extrnPop3Servers = (ArrayList)e.Session.Tag;
                    foreach(POP3_Client clnt in extrnPop3Servers){
                        POP3_MessagesInfo mInf = clnt.GetMessagesInfo();
                        foreach(POP3_MessageInfo msg in mInf.Messages){
                            // Message tag structure: pop3Client,messageNr in remote pop3 server.
                            e.Messages.AddMessage(msg.MessegeID,(int)msg.MessageSize,new object[]{clnt,msg.MessageNr});
                        }
                    }
                }
                //----------------------------------------------------------------------------------------------------//
            }
            catch(Exception x)
            {
                Error.DumpError(x,new System.Diagnostics.StackTrace());
            }
        }
        /// <summary>
        /// Gets specified IMAP folder's messges info.
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="folder">IMAP folder which messages info to get. Eg. 'Inbox'.</param>
        /// <param name="messages"></param>
        public void GetMessagesInfo(string userName,string folder,LumiSoft.Net.IMAP.Server.IMAP_Messages messages)
        {
            switch(m_DB_Type)
            {
                #region DB_Type.XML

                case DB_Type.XML:
                    string path = m_MailStorePath + "Mailboxes\\" + userName + "\\" + folder;

                    // Check if Directory exists, if not Create for Inbox only
                    if(!Directory.Exists(path)){
                        if(folder.ToLower().Trim() == "inbox"){
                            Directory.CreateDirectory(path);
                        }
                        else{
                            throw new Exception("Folder '" + folder + "' doesn't exist");
                        }
                    }

                    string[] files = Directory.GetFiles(path,"*.eml");

                    foreach(string file in files){
                        int messageSize = 0;
                        using(FileStream fStream = File.OpenRead(file)){
                            messageSize = (int)fStream.Length;
                        }

                        // date[yyyyMMddHHmmss]_int[uid]_int[flags]
                        string[] fileParts = Path.GetFileNameWithoutExtension(file).Split('_');
                        DateTime recieveDate = DateTime.ParseExact(fileParts[0],"yyyyMMddHHmmss",System.Globalization.DateTimeFormatInfo.InvariantInfo);
                        int      uid         = Convert.ToInt32(fileParts[1]);
                        LumiSoft.Net.IMAP.Server.IMAP_MessageFlags flags = (LumiSoft.Net.IMAP.Server.IMAP_MessageFlags)Enum.Parse(typeof(LumiSoft.Net.IMAP.Server.IMAP_MessageFlags),fileParts[2]);

                        messages.AddMessage(Path.GetFileNameWithoutExtension(file),uid,flags,messageSize,recieveDate);
                    }

                    break;

                #endregion

                #region DB_Type.MSSQL

                case DB_Type.MSSQL:
                    using(WSqlCommand sqlCmd = new WSqlCommand(m_ConStr,"lspr_GetMessageList")){
                        sqlCmd.AddParameter("@Mailbox",SqlDbType.NVarChar,userName);
                        sqlCmd.AddParameter("@Folder" ,SqlDbType.NVarChar,folder);

                        DataSet ds = sqlCmd.Execute();
                        ds.Tables[0].TableName = "lsMailStore";

                        foreach(DataRow dr in ds.Tables["lsMailStore"].Rows){
                            string   messageID = dr["MessageID"].ToString();
                            int      size      = Convert.ToInt32(dr["Size"]);
                            DateTime date      = Convert.ToDateTime(dr["Date"]);
                            int      flags     = Convert.ToInt32(dr["MessageFlags"]);
                            int      uid       = Convert.ToInt32(dr["UID"]);
                            messages.AddMessage(messageID,uid,(IMAP_MessageFlags)flags,size,date);
                        }
                    }
                    break;

                #endregion
            }
        }
Пример #29
0
        public static void QuickSend(LumiSoft.Net.Mime.Mime message)
        {
            if(message == null){
                throw new ArgumentNullException("message");
            }

            string from = "";
            if(message.MainEntity.From != null && message.MainEntity.From.Count > 0){
                from = ((MailboxAddress)message.MainEntity.From[0]).EmailAddress;
            }

            List<string> recipients = new List<string>();
            if(message.MainEntity.To != null){
				MailboxAddress[] addresses = message.MainEntity.To.Mailboxes;				
				foreach(MailboxAddress address in addresses){
					recipients.Add(address.EmailAddress);
				}
			}
			if(message.MainEntity.Cc != null){
				MailboxAddress[] addresses = message.MainEntity.Cc.Mailboxes;				
				foreach(MailboxAddress address in addresses){
					recipients.Add(address.EmailAddress);
				}
			}
			if(message.MainEntity.Bcc != null){
				MailboxAddress[] addresses = message.MainEntity.Bcc.Mailboxes;				
				foreach(MailboxAddress address in addresses){
					recipients.Add(address.EmailAddress);
				}

                // We must hide BCC
                message.MainEntity.Bcc.Clear();
			}

            foreach(string recipient in recipients){
                QuickSend(null,from,recipient,new MemoryStream(message.ToByteData()));
            }
        }
        private void POP3_Server_GetTopLines(object sender,LumiSoft.Net.POP3.Server.GetTopLines_Eventargs e)
        {
            /* If there is something stored to Tag, this means that message is reomte server message.
             * Message tag structure: pop3Client,messageNr in remote pop3 server.
            */

            try
            {
                // Get local message top lines
                if(e.Message.Tag == null){
                    e.LinesData = m_pAPI.GetMessageTopLines(e.Mailbox,"Inbox",e.MessageID,e.Lines);
                }
                // Get remote message top lines
                else{
                    object[] tag = (object[])e.Message.Tag;

                    POP3_Client clnt = (POP3_Client)tag[0];
                    e.LinesData = clnt.GetTopOfMessage(Convert.ToInt32(tag[1]),e.Lines);
                }
            }
            catch(Exception x)
            {
                Error.DumpError(x,new System.Diagnostics.StackTrace());
            }
        }