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 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);

            var mfd = new MapiFileDesc
            {
                position = -1
            };
            var runptr = ptra.ToInt64();

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

            fileCount = attachs.Count;
            return(ptra);
        }
Exemple #3
0
 protected internal MapiFileDescW(MapiFileDesc fileDesc)
 {
     reserved = fileDesc.reserved;
     flags    = fileDesc.flags;
     position = fileDesc.position;
     path     = fileDesc.path;
     name     = fileDesc.name;
     type     = fileDesc.type;
 }
Exemple #4
0
        private bool SaveAttachByName(string name, string savePath)
        {
            bool f      = true;
            Type fdtype = typeof(MapiFileDesc);
            int  fdsize = Marshal.SizeOf(fdtype);
            var  fdtmp  = new MapiFileDesc();
            var  runPtr = lastMsg.files.ToInt64();

            for (int i = 0; i < lastMsg.fileCount; i++)
            {
                var ptrDest = new IntPtr(runPtr);
                Marshal.PtrToStructure(ptrDest, 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)
                {
                    // ignored
                }
            }
            return(f);
        }
Exemple #5
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;
                }
            }
        }
Exemple #6
0
        private void GetAttachNames(out MailAttach[] att)
        {
            att = new MailAttach[lastMsg.fileCount];
            Type fdtype = typeof(MapiFileDesc);
            int  fdsize = Marshal.SizeOf(fdtype);
            var  fdtmp  = new MapiFileDesc();
            var  runptr = lastMsg.files.ToInt64();

            for (int i = 0; i < lastMsg.fileCount; i++)
            {
                var ptrDest = new IntPtr(runptr);
                Marshal.PtrToStructure(ptrDest, fdtmp);
                runptr += fdsize;
                att[i]  = new MailAttach();
                if (fdtmp.flags == 0)
                {
                    att[i].position = fdtmp.position;
                    att[i].name     = fdtmp.name;
                    att[i].path     = fdtmp.path;
                }
            }
        }
Exemple #7
0
		private bool SaveAttachByName(string name, string savepath)
		{
			bool f = true;
			Type fdtype = typeof (MapiFileDesc);
			int fdsize = Marshal.SizeOf(fdtype);
			var fdtmp = new MapiFileDesc();
			var 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 #8
0
		private void GetAttachNames(out MailAttach[] aat)
		{
			aat = new MailAttach[lastMsg.fileCount];
			Type fdtype = typeof (MapiFileDesc);
			int fdsize = Marshal.SizeOf(fdtype);
			var fdtmp = new MapiFileDesc();
			var 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;
				}
			}
		}
Exemple #9
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);

			var mfd = new MapiFileDesc {position = (-1)};
			var runptr = (int) ptra;
			for (int i = 0; i < attachs.Count; i++)
			{
				var 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;
		}