コード例 #1
0
ファイル: MapiApi.cs プロジェクト: muhliz25/cs-codebook
        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);
        }
コード例 #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);
        }
コード例 #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;
 }
コード例 #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);
        }
コード例 #5
0
ファイル: MapiApi.cs プロジェクト: muhliz25/cs-codebook
        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;
                }
            }
        }
コード例 #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;
                }
            }
        }
コード例 #7
0
ファイル: Win32Mapi.cs プロジェクト: TimVelo/StackBuilder
		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;
		}
コード例 #8
0
ファイル: Win32Mapi.cs プロジェクト: TimVelo/StackBuilder
		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;
				}
			}
		}
コード例 #9
0
ファイル: Win32Mapi.cs プロジェクト: TimVelo/StackBuilder
		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;
		}