Exemple #1
0
        private IntPtr AllocAttachs(out int fileCount)
        {
            fileCount = 0;
            if (attachs == null)
            {
                return(IntPtr.Zero);
            }
            if ((attachs.Count <= 0) || (attachs.Count > 100))
            {
                return(IntPtr.Zero);
            }

            Type   atype = typeof(MapiFileDesc);
            int    asize = Marshal.SizeOf(atype);
            IntPtr ptra  = Marshal.AllocHGlobal(attachs.Count * asize);

            MapiFileDesc mfd = new MapiFileDesc();

            mfd.position = -1;
            int runptr = (int)ptra;

            for (int i = 0; i < attachs.Count; i++)
            {
                string path = attachs[i] as string;
                mfd.name = Path.GetFileName(path);
                mfd.path = path;
                Marshal.StructureToPtr(mfd, (IntPtr)runptr, false);
                runptr += asize;
            }

            fileCount = attachs.Count;
            return(ptra);
        }
Exemple #2
0
        private bool SaveAttachByName(string name, string savepath)
        {
            bool         f      = true;
            Type         fdtype = typeof(MapiFileDesc);
            int          fdsize = Marshal.SizeOf(fdtype);
            MapiFileDesc fdtmp  = new MapiFileDesc();
            int          runptr = (int)lastMsg.files;

            for (int i = 0; i < lastMsg.fileCount; i++)
            {
                Marshal.PtrToStructure((IntPtr)runptr, fdtmp);
                runptr += fdsize;
                if (fdtmp.flags != 0)
                {
                    continue;
                }
                if (fdtmp.name == null)
                {
                    continue;
                }

                try
                {
                    if (name == fdtmp.name)
                    {
                        if (File.Exists(savepath))
                        {
                            File.Delete(savepath);
                        }
                        File.Move(fdtmp.path, savepath);
                    }
                }
                catch (Exception)
                {
                    f     = false;
                    error = 13;
                }

                try
                {
                    File.Delete(fdtmp.path);
                }
                catch (Exception)
                { }
            }
            return(f);
        }
Exemple #3
0
        private void GetAttachNames(out MailAttach[] aat)
        {
            aat = new MailAttach[lastMsg.fileCount];
            Type         fdtype = typeof(MapiFileDesc);
            int          fdsize = Marshal.SizeOf(fdtype);
            MapiFileDesc fdtmp  = new MapiFileDesc();
            int          runptr = (int)lastMsg.files;

            for (int i = 0; i < lastMsg.fileCount; i++)
            {
                Marshal.PtrToStructure((IntPtr)runptr, fdtmp);
                runptr += fdsize;
                aat[i]  = new MailAttach();
                if (fdtmp.flags == 0)
                {
                    aat[i].position = fdtmp.position;
                    aat[i].name     = fdtmp.name;
                    aat[i].path     = fdtmp.path;
                }
            }
        }