Example #1
0
        private void GetUserFolderMessage(string argsText)
        {
            /* C: GetUserFolderMessage <virtualServerID> "<folderOwnerUser>" "<folder>" "<messageID>"
               S: +OK <sizeInBytes>
               S: <messageData>
                            
                  Responses:
                    +OK               
                    -ERR <errorText>
            */

            try{
                string[] args = TextUtils.SplitQuotedString(argsText,' ',true);
                if(args.Length != 4){
                    WriteLine("-ERR Invalid arguments. Syntax: GetUserFolderMessage <virtualServerID> \"<folderOwnerUser>\" \"<folder>\" \"<messageID>\"");
                    return;
                }

                foreach(VirtualServer virtualServer in this.Server.MailServer.VirtualServers){
                    if(virtualServer.ID.ToLower() == args[0].ToLower()){ 
                        // TODO: handle no existent user
                        // TODO: handle no existent folder

                        EmailMessageItems msgItems = new EmailMessageItems(args[3],IMAP_MessageItems_enum.Message);
                        virtualServer.API.GetMessageItems(
                            "system",
                            args[1],
                            args[2],
                            msgItems
                        );

                        if(msgItems.MessageExists){
                            try{
                                WriteLine("+OK " + ConvertEx.ToString(msgItems.MessageStream.Length - msgItems.MessageStream.Position));
                                Write(msgItems.MessageStream);
                            }
                            finally{
                                msgItems.MessageStream.Close();
                            }
                        }
                        else{
                            WriteLine("-ERR Specified message doesn't exist !");
                        }
                                                
                        return;
                    }
                }

                WriteLine("-ERR Specified virtual server with ID '" + args[0] + "' doesn't exist !");
            }
            catch(Exception x){
                WriteLine("-ERR " + x.Message);
            }
        }
Example #2
0
        private void GetUserFolderMessagesInfo(string argsText)
        {
            try{
                string[] args = TextUtils.SplitQuotedString(argsText,' ',true);
                if(args.Length != 3){
                    WriteLine("-ERR Invalid arguments. Syntax: GetUserFolderMessagesInfo <virtualServerID> \"<user>\" \"<folder>\"");
                    return;
                }

                foreach(VirtualServer virtualServer in this.Server.MailServer.VirtualServers){
                    if(virtualServer.ID.ToLower() == args[0].ToLower()){ 
                        // TODO: handle no existent user
                        // TODO: handle no existent folder

                        DataSet ds = new DataSet();
                        ds.Tables.Add("MessagesInfo");
                        ds.Tables["MessagesInfo"].Columns.Add("ID");
                        ds.Tables["MessagesInfo"].Columns.Add("UID");  // REMOVE ME: Now needed for delete message.
                        ds.Tables["MessagesInfo"].Columns.Add("Size",typeof(long));
                        ds.Tables["MessagesInfo"].Columns.Add("Flags");
                        ds.Tables["MessagesInfo"].Columns.Add("Envelope");

                        List<IMAP_MessageInfo> messages = new List<IMAP_MessageInfo>();
                        virtualServer.API.GetMessagesInfo("system",args[1],args[2],messages);
                        foreach(IMAP_MessageInfo message in messages){
                            try{
                                DataRow dr = ds.Tables["MessagesInfo"].NewRow();
                                dr["ID"]    = message.ID;
                                dr["UID"]   = message.UID;
                                dr["Size"]  = message.Size;
                                dr["Flags"] = Net_Utils.ArrayToString(message.Flags," ");
                                
                                EmailMessageItems msgItems = new EmailMessageItems(message.ID,IMAP_MessageItems_enum.Header);
                                virtualServer.API.GetMessageItems("system",args[1],args[2],msgItems);
                                dr["Envelope"] = IMAP_t_Fetch_r_i_Envelope.ConstructEnvelope(Mail_Message.ParseFromByte(msgItems.Header));
                                ds.Tables["MessagesInfo"].Rows.Add(dr);
                            }
                            catch{
                            }
                        }
                        
                        // Compress data
                        byte[] dsZipped = CompressDataSet(ds);

                        WriteLine("+OK " + dsZipped.Length);
                        Write(dsZipped);
                        return;
                    }
                }

                WriteLine("-ERR Specified virtual server with ID '" + args[0] + "' doesn't exist !");
            }
            catch(Exception x){
                WriteLine("-ERR " + x.Message);
            }
        }