Ejemplo n.º 1
0
        /// <summary>
        /// Gets server user folders and binds them to this, if not binded already.
        /// </summary>
        private void Bind()
        {
            /* GetUserFolderAcl <virtualServerID> <userID> "<folderName>"
             *    Responses:
             +OK <sizeOfData>
             *      <data>
             *
             + ERR <errorText>
             */

            lock (m_pFolder.User.VirtualServer.Server.LockSynchronizer){
                // Call TCP GetUserFolderAcl
                m_pFolder.User.VirtualServer.Server.TcpClient.TcpStream.WriteLine("GetUserFolderAcl " +
                                                                                  m_pFolder.User.VirtualServer.VirtualServerID + " " +
                                                                                  m_pFolder.User.UserID + " \"" +
                                                                                  m_pFolder.FolderFullPath
                                                                                  );

                string response = m_pFolder.User.VirtualServer.Server.ReadLine();
                if (!response.ToUpper().StartsWith("+OK"))
                {
                    throw new Exception(response);
                }

                int          sizeOfData = Convert.ToInt32(response.Split(new char[] { ' ' }, 2)[1]);
                MemoryStream ms         = new MemoryStream();
                m_pFolder.User.VirtualServer.Server.TcpClient.TcpStream.ReadFixedCount(ms, sizeOfData);

                // Decompress dataset
                DataSet ds = Utils.DecompressDataSet(ms);

                if (ds.Tables.Contains("ACL"))
                {
                    foreach (DataRow dr in ds.Tables["ACL"].Rows)
                    {
                        m_pAclEntries.Add(new UserFolderAcl(
                                              this,
                                              m_pFolder,
                                              dr["User"].ToString(),
                                              IMAP_Utils.ACL_From_String(dr["Permissions"].ToString())
                                              ));
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets myrights to specified folder.
        /// </summary>
        /// <param name="folderName"></param>
        /// <returns></returns>
        public IMAP_ACL_Flags GetFolderMyrights(string folderName)
        {
            if (!m_Connected)
            {
                throw new Exception("You must connect first !");
            }
            if (!m_Authenticated)
            {
                throw new Exception("You must authenticate first !");
            }

            IMAP_ACL_Flags aclFlags = IMAP_ACL_Flags.None;

            m_pSocket.SendLine("a1 MYRIGHTS \"" + EncodeUtf7(folderName) + "\"");

            // Must get lines with * and cmdTag + OK or cmdTag BAD/NO
            string reply = m_pSocket.ReadLine();

            if (reply.StartsWith("*"))
            {
                // Read multiline response
                while (reply.StartsWith("*"))
                {
                    // Get rid of *
                    reply = reply.Substring(1).Trim();

                    if (reply.ToUpper().IndexOf("MYRIGHTS") > -1)
                    {
                        aclFlags = IMAP_Utils.ACL_From_String(reply.Substring(0, reply.IndexOf(" ")).Trim());
                    }

                    reply = m_pSocket.ReadLine();
                }
            }

            reply = reply.Substring(reply.IndexOf(" ")).Trim();             // Remove Cmd tag

            if (!reply.ToUpper().StartsWith("OK"))
            {
                throw new Exception("Server returned:" + reply);
            }

            return(aclFlags);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Parses ACL entry from IMAP ACL response string.
 /// </summary>
 /// <param name="aclResponseString">IMAP ACL response string.</param>
 /// <returns></returns>
 internal static IMAP_Acl Parse(string aclResponseString)
 {
     string[] args = TextUtils.SplitQuotedString(aclResponseString, ' ', true);
     return(new IMAP_Acl(args[1], IMAP_Utils.ACL_From_String(args[2])));
 }
Ejemplo n.º 4
0
 private void Bind()
 {
     lock (this.m_pFolder.User.VirtualServer.Server.LockSynchronizer)
     {
         this.m_pFolder.User.VirtualServer.Server.TCP_Client.TcpStream.WriteLine(string.Concat(new string[]
         {
             "GetUserFolderAcl ",
             this.m_pFolder.User.VirtualServer.VirtualServerID,
             " ",
             this.m_pFolder.User.UserID,
             " \"",
             this.m_pFolder.FolderFullPath
         }));
         string text = this.m_pFolder.User.VirtualServer.Server.ReadLine();
         if (!text.ToUpper().StartsWith("+OK"))
         {
             throw new Exception(text);
         }
         int num = Convert.ToInt32(text.Split(new char[]
         {
             ' '
         }, 2)[1]);
         MemoryStream memoryStream = new MemoryStream();
         this.m_pFolder.User.VirtualServer.Server.TCP_Client.TcpStream.ReadFixedCount(memoryStream, (long)num);
         DataSet dataSet = Utils.DecompressDataSet(memoryStream);
         if (dataSet.Tables.Contains("ACL"))
         {
             foreach (DataRow dataRow in dataSet.Tables["ACL"].Rows)
             {
                 this.m_pAclEntries.Add(new UserFolderAcl(this, this.m_pFolder, dataRow["User"].ToString(), IMAP_Utils.ACL_From_String(dataRow["Permissions"].ToString())));
             }
         }
     }
 }