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