Example #1
0
        public override IFolderObject Restore(byte[] data, bool forName = false)
        {
            MemoryStream ms = new MemoryStream(data);
            BinaryReader r  = new BinaryReader(ms, Encoding.Default);

            if (r.ReadInt32() == 0)             // key item
            {
                string path = r.ReadString();
                //Debug.WriteLine("KEY: "+path);
                FolderAttributes attrs = (FolderAttributes)r.ReadInt32();
                return(new KeyItem(PathData, idListAbsolute, root, path, attrs));
            }
            else                                                // value item
            {
                string path      = null;
                string valueName = string.Empty;
                try
                {
                    // Debug.WriteLine("Value: " + data);
                    if (r.BaseStream.Position < r.BaseStream.Length)
                    {
                        path = r.ReadBoolean() ? r.ReadString() : null;
                    }
                    if (r.BaseStream.Position < r.BaseStream.Length)
                    {
                        valueName = r.ReadString();
                    }
                }
                catch (Exception)
                {
                }
                return(new ValueItem(PathData, root, path, valueName));
            }
        }
Example #2
0
        public Folder(byte[][] pathData, IdList idlist, string root, string path, FolderAttributes attrs, IFileObject fo, IShellView sv, IFolderObject parrent)
        {
            this.parrent = parrent;
            columns      = new ColumnCollection();
            columns.Add(ColName);
            columns.Add(ColAttr);
            columns.Add(ColPerm1);
            columns.Add(ColPerm2);
            columns.Add(ColFileSize);
            columns.Add(ColDate);
            columns.Add(ColTime);
            columns.Add(ColLinkTo);

            base.ShellView = sv;
            this.attrs     = attrs;
            this.root      = root;
            this.path      = path;
            this.fo        = fo;

            if (string.IsNullOrEmpty(root))
            {
                base.SetPath(string.Format("{0}", path));
            }
            else
            {
                base.SetPath(string.Format("{0}{1}{2}", root, FD, path));
            }

            base.SetPath(pathData);
            base.SetIdList(idlist);
        }
		/// <summary>
		/// Initializes a new instance of the <see cref="MailKit.Net.Imap.ImapFolderConstructorArgs"/> class.
		/// </summary>
		/// <param name="engine">The IMAP command engine.</param>
		/// <param name="encodedName">The encoded name.</param>
		/// <param name="attributes">The attributes.</param>
		/// <param name="delim">The directory separator.</param>
		internal ImapFolderConstructorArgs (ImapEngine engine, string encodedName, FolderAttributes attributes, char delim)
		{
			FullName = engine.DecodeMailboxName (encodedName);
			Name = GetBaseName (FullName, delim);
			DirectorySeparator = delim;
			EncodedName = encodedName;
			Attributes = attributes;
			Engine = engine;
		}
Example #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MailKit.Net.Imap.ImapFolder"/> class.
 /// </summary>
 /// <param name="engine">The IMAP engine.</param>
 /// <param name="encodedName">The encoded name.</param>
 /// <param name="attrs">The folder attributes.</param>
 /// <param name="delim">The path delimeter.</param>
 internal ImapFolder(ImapEngine engine, string encodedName, FolderAttributes attrs, char delim)
 {
     FullName = ImapEncoding.Decode (encodedName);
     Name = GetBaseName (FullName, delim);
     DirectorySeparator = delim;
     EncodedName = encodedName;
     Attributes = attrs;
     Engine = engine;
 }
Example #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MailKit.Net.Imap.ImapFolderConstructorArgs"/> class.
 /// </summary>
 /// <param name="engine">The IMAP command engine.</param>
 /// <param name="encodedName">The encoded name.</param>
 /// <param name="attributes">The attributes.</param>
 /// <param name="delim">The directory separator.</param>
 internal ImapFolderConstructorArgs(ImapEngine engine, string encodedName, FolderAttributes attributes, char delim)
 {
     FullName           = engine.DecodeMailboxName(encodedName);
     Name               = GetBaseName(FullName, delim);
     DirectorySeparator = delim;
     EncodedName        = encodedName;
     Attributes         = attributes;
     Engine             = engine;
 }
        public NsExtensionAttribute(NsTarget target, string name, FolderAttributes attributes)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            this.target     = target;
            this.name       = name;
            this.attributes = attributes;
        }
Example #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MailKit.Net.Imap.ImapFolder"/> class.
        /// </summary>
        /// <param name="engine">The IMAP engine.</param>
        /// <param name="encodedName">The encoded name.</param>
        /// <param name="attrs">The folder attributes.</param>
        /// <param name="delim">The path delimeter.</param>
        internal ImapFolder(ImapEngine engine, string encodedName, FolderAttributes attrs, char delim)
        {
            FullName = engine.DecodeMailboxName (encodedName);
            Name = GetBaseName (FullName, delim);
            DirectorySeparator = delim;
            EncodedName = encodedName;
            Attributes = attrs;
            Engine = engine;

            engine.Disconnected += (sender, e) => {
                Access = FolderAccess.None;
            };
        }
Example #8
0
        protected KeyItem(byte[][] pathData, IdList idlist, RegistryKey root, string path, FolderAttributes attrs)
        {
            if (root == null)
            {
                throw new ArgumentNullException("root");
            }

            this.root  = root;
            this.path  = path;
            this.attrs = attrs;

            base.SetPath(pathData);
            base.SetPath(string.Format("{0}\\{1}", root.Name, path));
            base.SetIdList(idlist);
        }
        static void AssertFolder(IMailFolder folder, string fullName, FolderAttributes attributes, bool subscribed, ulong highestmodseq, int count, int recent, uint uidnext, uint validity, int unread)
        {
            if (subscribed)
            {
                attributes |= FolderAttributes.Subscribed;
            }

            Assert.AreEqual(fullName, folder.FullName, "FullName");
            Assert.AreEqual(attributes, folder.Attributes, "Attributes");
            Assert.AreEqual(subscribed, folder.IsSubscribed, "IsSubscribed");
            Assert.AreEqual(highestmodseq, folder.HighestModSeq, "HighestModSeq");
            Assert.AreEqual(count, folder.Count, "Count");
            Assert.AreEqual(recent, folder.Recent, "Recent");
            Assert.AreEqual(unread, folder.Unread, "Unread");
            Assert.AreEqual(uidnext, folder.UidNext.HasValue ? folder.UidNext.Value.Id : (uint)0, "UidNext");
            Assert.AreEqual(validity, folder.UidValidity, "UidValidity");
        }
Example #10
0
        public override void NewFolder()
        {
            string spath = CreateNewFolder(path, "New Folder");

            if (string.IsNullOrEmpty(spath))
            {
                return;
            }
            //refrash all views
            IntPtr pParrent = ItemIdList.Create(null, PathData).Ptr;

            Shell32.SHChangeNotify(ShellChangeEvents.UpdateDir,
                                   ShellChangeFlags.IdList | ShellChangeFlags.Flush,
                                   pParrent,
                                   IntPtr.Zero);
            Marshal.FreeCoTaskMem(pParrent);
            //

            using (MemoryStream ms = new MemoryStream())
            {
                FolderAttributes newFolderAttrs = FolderAttributes.Folder | FolderAttributes.HasPropSheet | FolderAttributes.CanMove | FolderAttributes.CanDelete | FolderAttributes.CanRename | FolderAttributes.CanCopy | FolderAttributes.CanLink | FolderAttributes.Browsable | FolderAttributes.DropTarget;
                BinaryWriter     w = new BinaryWriter(ms, Encoding.Default);
                w.Write(0);
                w.Write(string.Format("{0}{1}{2}", path, FD, spath));
                w.Write((int)newFolderAttrs);
                IFileObject foNew = new FileObject();
                foNew.Name     = spath;
                foNew.IsFolder = true;
                byte[] btFo = FileObject.ToByteArray(foNew);
                w.Write((int)btFo.Length);
                w.Write(btFo, 0, btFo.Length);
                byte[] persist = ms.ToArray();

                IntPtr pNewFolder = ItemIdList.Create(null, new byte[][] { persist }).Ptr;
                if (ShellView != null)
                {
                    ShellView.SelectItem(pNewFolder, _SVSIF.SVSI_EDIT | _SVSIF.SVSI_FOCUSED | _SVSIF.SVSI_ENSUREVISIBLE);
                }
                Marshal.FreeCoTaskMem(pNewFolder);
            }
        }
Example #11
0
        private bool Matches(IFolderObject folderObj)
        {
            FolderAttributes attrs = folderObj.Attributes;

            bool hidden        = (attrs & FolderAttributes.Hidden) != FolderAttributes.None;
            bool includeHidden = (opts & EnumOptions.IncludeHidden) == EnumOptions.IncludeHidden;

            bool folder            = (attrs & FolderAttributes.Folder) != FolderAttributes.None;
            bool includeFolders    = (opts & EnumOptions.Folders) == EnumOptions.Folders;
            bool includeNonFolders = (opts & EnumOptions.NonFolders) == EnumOptions.NonFolders;

            bool storage        = (attrs & (FolderAttributes.StorageAncestor | FolderAttributes.StorageAncestor)) != FolderAttributes.None;
            bool includeStorage = (opts & EnumOptions.Storage) == EnumOptions.Storage;

            bool share         = (attrs & FolderAttributes.Share) != FolderAttributes.None;
            bool includeShares = (opts & EnumOptions.Shareable) == EnumOptions.Shareable;

            return
                ((hidden ? includeHidden : true) &&
                 (folder ? includeFolders : includeNonFolders) &&
                 (storage ? includeStorage : true) &&
                 (share ? includeShares : true));
        }
Example #12
0
		internal void UpdateAttributes (FolderAttributes attrs)
		{
			Attributes = attrs;
		}
Example #13
0
		static void AssertFolder (IMailFolder folder, string fullName, FolderAttributes attributes, bool subscribed, ulong highestmodseq, int count, int recent, uint uidnext, uint validity, int unread)
		{
			if (subscribed)
				attributes |= FolderAttributes.Subscribed;

			Assert.AreEqual (fullName, folder.FullName, "FullName");
			Assert.AreEqual (attributes, folder.Attributes, "Attributes");
			Assert.AreEqual (subscribed, folder.IsSubscribed, "IsSubscribed");
			Assert.AreEqual (highestmodseq, folder.HighestModSeq, "HighestModSeq");
			Assert.AreEqual (count, folder.Count, "Count");
			Assert.AreEqual (recent, folder.Recent, "Recent");
			Assert.AreEqual (unread, folder.Unread, "Unread");
			Assert.AreEqual (uidnext, folder.UidNext.HasValue ? folder.UidNext.Value.Id : (uint) 0, "UidNext");
			Assert.AreEqual (validity, folder.UidValidity, "UidValidity");
		}
Example #14
0
        public override void CopyItems(IFolderObject fo, List <string> lItems)
        {
            FolderAttributes newFolderAttrs = FolderAttributes.Folder | FolderAttributes.HasPropSheet |
                                              FolderAttributes.CanMove | FolderAttributes.CanDelete |
                                              FolderAttributes.CanRename | FolderAttributes.CanCopy |
                                              FolderAttributes.CanLink | FolderAttributes.Browsable |
                                              FolderAttributes.DropTarget;

            FolderAttributes newFileAttrs = FolderAttributes.HasPropSheet | FolderAttributes.CanMove |
                                            FolderAttributes.CanDelete | FolderAttributes.CanRename |
                                            FolderAttributes.CanCopy | FolderAttributes.CanLink |
                                            FolderAttributes.Browsable | FolderAttributes.DropTarget;

            List <string> folders = new List <string>();
            List <string> files   = new List <string>();
            CommandResult cr      = Copy(fo.PathString, lItems, ref folders, ref files);

            if (!cr.IsSuccess)
            {
                cr.ShowMessage();
                return;
            }

            /*
             * foreach (string folder in folders)
             *  {
             *  using (MemoryStream ms = new MemoryStream())
             *  {
             *      BinaryWriter w = new BinaryWriter(ms, Encoding.Default);
             *      w.Write(0);
             *      w.Write(folder);
             *      w.Write((int)newFolderAttrs);
             *      byte[] persist = ms.ToArray();
             *
             *      var lst = PathData.ToList();
             *      lst.Add(persist);
             *
             *      IntPtr pNew = ItemIdList.Create(null, lst.ToArray()).Ptr;
             *      Shell32.SHChangeNotify(
             *          ShellChangeEvents.MkDir,
             *          ShellChangeFlags.IdList | ShellChangeFlags.Flush,
             *          pNew,
             *          IntPtr.Zero);
             *      Marshal.FreeCoTaskMem(pNew);
             *  }
             *  }
             *
             * foreach (string file in files)
             * {
             *  using (MemoryStream ms = new MemoryStream())
             *  {
             *      BinaryWriter w = new BinaryWriter(ms, Encoding.Default);
             *      w.Write(1);
             *      w.Write(file);
             *      w.Write((int)newFileAttrs);
             *      byte[] persist = ms.ToArray();
             *
             *      var lst = PathData.ToList();
             *      lst.Add(persist);
             *
             *      IntPtr pNew = ItemIdList.Create(null, lst.ToArray()).Ptr;
             *      Shell32.SHChangeNotify(
             *          ShellChangeEvents.Create,
             *          ShellChangeFlags.IdList | ShellChangeFlags.Flush,
             *          pNew,
             *          IntPtr.Zero);
             *      Marshal.FreeCoTaskMem(pNew);
             *  }
             * }
             */
            IntPtr pCurrObj = ItemIdList.Create(null, fo.PathData).Ptr;

            Shell32.SHChangeNotify(ShellChangeEvents.UpdateDir,
                                   ShellChangeFlags.IdList | ShellChangeFlags.Flush,
                                   pCurrObj,
                                   IntPtr.Zero);
            Marshal.FreeCoTaskMem(pCurrObj);
        }
Example #15
0
        public override IFolderObject Restore(byte[] data, bool forName = false)
        {
            using (MemoryStream ms = new MemoryStream(data))
            {
                BinaryReader r = new BinaryReader(ms, Encoding.Default);

                if (r.ReadInt32() == 0) // key item
                {
                    string path = r.ReadString();
                    //Debug.WriteLine("KEY: "+path);
                    FolderAttributes attrs = (FolderAttributes)r.ReadInt32();

                    if (attrs != FolderAttributes.None)
                    {
                        int        nDataLen = r.ReadInt32();
                        byte[]     btFo     = r.ReadBytes(nDataLen);
                        FileObject fo       = FileObject.ToObject(btFo);

                        //Folder.ItemsIcons = ItemsIcons;

                        Folder folder = new Folder(PathData, idListAbsolute, "", path, attrs, fo, ShellView, this);
                        if (ItemsIcons.ContainsKey("folder"))
                        {
                            folder.Icons = ItemsIcons["folder"];
                        }
                        return(folder);
                    }
                    else
                    {
                        Folder folder = new Folder(PathData, idListAbsolute, "", path, attrs, null, ShellView, this);
                        if (ItemsIcons.ContainsKey("folder"))
                        {
                            folder.Icons = ItemsIcons["folder"];
                        }
                        return(folder);
                    }
                }
                else                                    // value item
                {
                    int        nDataLen = r.ReadInt32();
                    byte[]     btFo     = r.ReadBytes(nDataLen);
                    FileObject fo       = FileObject.ToObject(btFo);

                    string path      = null;
                    string valueName = string.Empty;
                    try
                    {
                        // Debug.WriteLine("Value: " + data);
                        if (r.BaseStream.Position < r.BaseStream.Length)
                        {
                            path = r.ReadBoolean() ? r.ReadString() : null;
                        }
                        if (r.BaseStream.Position < r.BaseStream.Length)
                        {
                            valueName = r.ReadString();
                        }
                    }
                    catch (Exception)
                    {
                    }

                    Item it = new Item(PathData, "", path, valueName, fo, this, ShellView);

                    string ext = IconHelper.GetExtension(valueName);
                    if (string.IsNullOrEmpty(ext) && ItemsIcons.ContainsKey("no"))
                    {
                        it.Icons = ItemsIcons["no"];
                    }

                    if (!string.IsNullOrEmpty(ext) && ItemsIcons.ContainsKey(ext))
                    {
                        it.Icons = ItemsIcons[ext];
                    }

                    return(it);
                }
            }


            if (items == null)
            {
                items = GetItems(null) as ArrayList;
            }
            //return new Item(PathData, BitConverter.ToInt32(data, 0), BitConverter.ToInt32(data, 0).ToString());
            //Item it = (Item)(items[BitConverter.ToInt32(data, 0)]);
            //it.SetPath(PathData);
            try
            {
                return((IFolderObject)items[BitConverter.ToInt32(data, 0)]);
            }
            catch (Exception)
            {
                return(this);
            }
        }