mirror of
https://github.com/greenshot/greenshot
synced 2025-07-31 12:10:15 -07:00
Fixed MAPI Recipient properties
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2488 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
442a978d13
commit
2b4df68c1f
2 changed files with 160 additions and 180 deletions
|
@ -46,7 +46,7 @@ namespace Greenshot.Helpers {
|
||||||
public class MapiMailMessage {
|
public class MapiMailMessage {
|
||||||
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(MapiMailMessage));
|
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(MapiMailMessage));
|
||||||
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Helper Method for creating an Email with Attachment
|
/// Helper Method for creating an Email with Attachment
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -61,12 +61,12 @@ namespace Greenshot.Helpers {
|
||||||
if (!string.IsNullOrEmpty(conf.MailApiCC)) {
|
if (!string.IsNullOrEmpty(conf.MailApiCC)) {
|
||||||
message._recipientCollection.Add(new Recipient(conf.MailApiCC, RecipientType.CC));
|
message._recipientCollection.Add(new Recipient(conf.MailApiCC, RecipientType.CC));
|
||||||
}
|
}
|
||||||
if (!string.IsNullOrEmpty(conf.MailApiTo)) {
|
if (!string.IsNullOrEmpty(conf.MailApiBCC)) {
|
||||||
message._recipientCollection.Add(new Recipient(conf.MailApiBCC, RecipientType.BCC));
|
message._recipientCollection.Add(new Recipient(conf.MailApiBCC, RecipientType.BCC));
|
||||||
}
|
}
|
||||||
message.ShowDialog();
|
message.ShowDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Helper Method for creating an Email with Image Attachment
|
/// Helper Method for creating an Email with Image Attachment
|
||||||
|
@ -92,7 +92,7 @@ namespace Greenshot.Helpers {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#region Private MapiFileDescriptor Class
|
#region Private MapiFileDescriptor Class
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||||
private class MapiFileDescriptor {
|
private class MapiFileDescriptor {
|
||||||
public int reserved = 0;
|
public int reserved = 0;
|
||||||
|
@ -102,11 +102,11 @@ namespace Greenshot.Helpers {
|
||||||
public string name = null;
|
public string name = null;
|
||||||
public IntPtr type = IntPtr.Zero;
|
public IntPtr type = IntPtr.Zero;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Private MapiFileDescriptor Class
|
#endregion Private MapiFileDescriptor Class
|
||||||
|
|
||||||
#region Enums
|
#region Enums
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Specifies the valid RecipientTypes for a Recipient.
|
/// Specifies the valid RecipientTypes for a Recipient.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -115,32 +115,32 @@ namespace Greenshot.Helpers {
|
||||||
/// Recipient will be in the TO list.
|
/// Recipient will be in the TO list.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
To = 1,
|
To = 1,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Recipient will be in the CC list.
|
/// Recipient will be in the CC list.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
CC = 2,
|
CC = 2,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Recipient will be in the BCC list.
|
/// Recipient will be in the BCC list.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
BCC = 3
|
BCC = 3
|
||||||
};
|
};
|
||||||
|
|
||||||
#endregion Enums
|
#endregion Enums
|
||||||
|
|
||||||
#region Member Variables
|
#region Member Variables
|
||||||
|
|
||||||
private string _subject;
|
private string _subject;
|
||||||
private string _body;
|
private string _body;
|
||||||
private RecipientCollection _recipientCollection;
|
private RecipientCollection _recipientCollection;
|
||||||
private List<string> _files;
|
private List<string> _files;
|
||||||
private ManualResetEvent _manualResetEvent;
|
private ManualResetEvent _manualResetEvent;
|
||||||
|
|
||||||
#endregion Member Variables
|
#endregion Member Variables
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a blank mail message.
|
/// Creates a blank mail message.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -149,14 +149,14 @@ namespace Greenshot.Helpers {
|
||||||
_recipientCollection = new RecipientCollection();
|
_recipientCollection = new RecipientCollection();
|
||||||
_manualResetEvent = new ManualResetEvent(false);
|
_manualResetEvent = new ManualResetEvent(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new mail message with the specified subject.
|
/// Creates a new mail message with the specified subject.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public MapiMailMessage(string subject) : this() {
|
public MapiMailMessage(string subject) : this() {
|
||||||
_subject = subject;
|
_subject = subject;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new mail message with the specified subject and body.
|
/// Creates a new mail message with the specified subject and body.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -164,45 +164,57 @@ namespace Greenshot.Helpers {
|
||||||
_subject = subject;
|
_subject = subject;
|
||||||
_body = body;
|
_body = body;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Constructors
|
#endregion Constructors
|
||||||
|
|
||||||
#region Public Properties
|
#region Public Properties
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the subject of this mail message.
|
/// Gets or sets the subject of this mail message.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Subject {
|
public string Subject {
|
||||||
get { return _subject; }
|
get {
|
||||||
set { _subject = value; }
|
return _subject;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
_subject = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the body of this mail message.
|
/// Gets or sets the body of this mail message.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Body {
|
public string Body {
|
||||||
get { return _body; }
|
get {
|
||||||
set { _body = value; }
|
return _body;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
_body = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the recipient list for this mail message.
|
/// Gets the recipient list for this mail message.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public RecipientCollection Recipients {
|
public RecipientCollection Recipients {
|
||||||
get { return _recipientCollection; }
|
get {
|
||||||
|
return _recipientCollection;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the file list for this mail message.
|
/// Gets the file list for this mail message.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<string> Files {
|
public List<string> Files {
|
||||||
get { return _files; }
|
get {
|
||||||
|
return _files;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Public Properties
|
#endregion Public Properties
|
||||||
|
|
||||||
#region Public Methods
|
#region Public Methods
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Displays the mail message dialog asynchronously.
|
/// Displays the mail message dialog asynchronously.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -213,42 +225,42 @@ namespace Greenshot.Helpers {
|
||||||
t.Name = "Create MAPI mail";
|
t.Name = "Create MAPI mail";
|
||||||
t.SetApartmentState(ApartmentState.STA);
|
t.SetApartmentState(ApartmentState.STA);
|
||||||
t.Start();
|
t.Start();
|
||||||
|
|
||||||
// only return when the new thread has built it's interop representation
|
// only return when the new thread has built it's interop representation
|
||||||
_manualResetEvent.WaitOne();
|
_manualResetEvent.WaitOne();
|
||||||
_manualResetEvent.Reset();
|
_manualResetEvent.Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Public Methods
|
#endregion Public Methods
|
||||||
|
|
||||||
#region Private Methods
|
#region Private Methods
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sends the mail message.
|
/// Sends the mail message.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void _ShowMail() {
|
private void _ShowMail() {
|
||||||
MAPIHelperInterop.MapiMessage message = new MAPIHelperInterop.MapiMessage();
|
MAPIHelperInterop.MapiMessage message = new MAPIHelperInterop.MapiMessage();
|
||||||
|
|
||||||
using (RecipientCollection.InteropRecipientCollection interopRecipients = _recipientCollection.GetInteropRepresentation()) {
|
using (RecipientCollection.InteropRecipientCollection interopRecipients = _recipientCollection.GetInteropRepresentation()) {
|
||||||
message.Subject = _subject;
|
message.Subject = _subject;
|
||||||
message.NoteText = _body;
|
message.NoteText = _body;
|
||||||
|
|
||||||
message.Recipients = interopRecipients.Handle;
|
message.Recipients = interopRecipients.Handle;
|
||||||
message.RecipientCount = _recipientCollection.Count;
|
message.RecipientCount = _recipientCollection.Count;
|
||||||
|
|
||||||
// Check if we need to add attachments
|
// Check if we need to add attachments
|
||||||
if (_files.Count > 0) {
|
if (_files.Count > 0) {
|
||||||
// Add attachments
|
// Add attachments
|
||||||
message.Files = _AllocAttachments(out message.FileCount);
|
message.Files = _AllocAttachments(out message.FileCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Signal the creating thread (make the remaining code async)
|
// Signal the creating thread (make the remaining code async)
|
||||||
_manualResetEvent.Set();
|
_manualResetEvent.Set();
|
||||||
|
|
||||||
const int MAPI_DIALOG = 0x8;
|
const int MAPI_DIALOG = 0x8;
|
||||||
//const int MAPI_LOGON_UI = 0x1;
|
//const int MAPI_LOGON_UI = 0x1;
|
||||||
int error = MAPIHelperInterop.MAPISendMail(IntPtr.Zero, IntPtr.Zero, message, MAPI_DIALOG, 0);
|
int error = MAPIHelperInterop.MAPISendMail(IntPtr.Zero, IntPtr.Zero, message, MAPI_DIALOG, 0);
|
||||||
|
|
||||||
if (_files.Count > 0) {
|
if (_files.Count > 0) {
|
||||||
// Deallocate the files
|
// Deallocate the files
|
||||||
_DeallocFiles(message);
|
_DeallocFiles(message);
|
||||||
|
@ -268,23 +280,20 @@ namespace Greenshot.Helpers {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deallocates the files in a message.
|
/// Deallocates the files in a message.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">The message to deallocate the files from.</param>
|
/// <param name="message">The message to deallocate the files from.</param>
|
||||||
private void _DeallocFiles(MAPIHelperInterop.MapiMessage message)
|
private void _DeallocFiles(MAPIHelperInterop.MapiMessage message) {
|
||||||
{
|
if (message.Files != IntPtr.Zero) {
|
||||||
if (message.Files != IntPtr.Zero)
|
|
||||||
{
|
|
||||||
Type fileDescType = typeof(MapiFileDescriptor);
|
Type fileDescType = typeof(MapiFileDescriptor);
|
||||||
int fsize = Marshal.SizeOf(fileDescType);
|
int fsize = Marshal.SizeOf(fileDescType);
|
||||||
|
|
||||||
// Get the ptr to the files
|
// Get the ptr to the files
|
||||||
int runptr = (int)message.Files;
|
int runptr = (int)message.Files;
|
||||||
// Release each file
|
// Release each file
|
||||||
for (int i = 0; i < message.FileCount; i++)
|
for (int i = 0; i < message.FileCount; i++) {
|
||||||
{
|
|
||||||
Marshal.DestroyStructure((IntPtr)runptr, fileDescType);
|
Marshal.DestroyStructure((IntPtr)runptr, fileDescType);
|
||||||
runptr += fsize;
|
runptr += fsize;
|
||||||
}
|
}
|
||||||
|
@ -292,44 +301,40 @@ namespace Greenshot.Helpers {
|
||||||
Marshal.FreeHGlobal(message.Files);
|
Marshal.FreeHGlobal(message.Files);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allocates the file attachments
|
/// Allocates the file attachments
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fileCount"></param>
|
/// <param name="fileCount"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private IntPtr _AllocAttachments(out int fileCount)
|
private IntPtr _AllocAttachments(out int fileCount) {
|
||||||
{
|
|
||||||
fileCount = 0;
|
fileCount = 0;
|
||||||
if (_files == null)
|
if (_files == null) {
|
||||||
{
|
|
||||||
return IntPtr.Zero;
|
return IntPtr.Zero;
|
||||||
}
|
}
|
||||||
if ((_files.Count <= 0) || (_files.Count > 100))
|
if ((_files.Count <= 0) || (_files.Count > 100)) {
|
||||||
{
|
|
||||||
return IntPtr.Zero;
|
return IntPtr.Zero;
|
||||||
}
|
}
|
||||||
|
|
||||||
Type atype = typeof(MapiFileDescriptor);
|
Type atype = typeof(MapiFileDescriptor);
|
||||||
int asize = Marshal.SizeOf(atype);
|
int asize = Marshal.SizeOf(atype);
|
||||||
IntPtr ptra = Marshal.AllocHGlobal(_files.Count * asize);
|
IntPtr ptra = Marshal.AllocHGlobal(_files.Count * asize);
|
||||||
|
|
||||||
MapiFileDescriptor mfd = new MapiFileDescriptor();
|
MapiFileDescriptor mfd = new MapiFileDescriptor();
|
||||||
mfd.position = -1;
|
mfd.position = -1;
|
||||||
int runptr = (int)ptra;
|
int runptr = (int)ptra;
|
||||||
for (int i = 0; i < _files.Count; i++)
|
for (int i = 0; i < _files.Count; i++) {
|
||||||
{
|
|
||||||
string path = _files[i] as string;
|
string path = _files[i] as string;
|
||||||
mfd.name = Path.GetFileName(path);
|
mfd.name = Path.GetFileName(path);
|
||||||
mfd.path = path;
|
mfd.path = path;
|
||||||
Marshal.StructureToPtr(mfd, (IntPtr)runptr, false);
|
Marshal.StructureToPtr(mfd, (IntPtr)runptr, false);
|
||||||
runptr += asize;
|
runptr += asize;
|
||||||
}
|
}
|
||||||
|
|
||||||
fileCount = _files.Count;
|
fileCount = _files.Count;
|
||||||
return ptra;
|
return ptra;
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum MAPI_CODES {
|
private enum MAPI_CODES {
|
||||||
SUCCESS = 0,
|
SUCCESS = 0,
|
||||||
USER_ABORT = 1,
|
USER_ABORT = 1,
|
||||||
|
@ -364,9 +369,9 @@ namespace Greenshot.Helpers {
|
||||||
/// Logs any Mapi errors.
|
/// Logs any Mapi errors.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private string GetMapiError(MAPI_CODES errorCode) {
|
private string GetMapiError(MAPI_CODES errorCode) {
|
||||||
|
|
||||||
string error = string.Empty;
|
string error = string.Empty;
|
||||||
|
|
||||||
switch (errorCode) {
|
switch (errorCode) {
|
||||||
case MAPI_CODES.USER_ABORT:
|
case MAPI_CODES.USER_ABORT:
|
||||||
error = "User Aborted.";
|
error = "User Aborted.";
|
||||||
|
@ -453,29 +458,27 @@ namespace Greenshot.Helpers {
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
#endregion Private Methods
|
#endregion Private Methods
|
||||||
|
|
||||||
#region Private MAPIHelperInterop Class
|
#region Private MAPIHelperInterop Class
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Internal class for calling MAPI APIs
|
/// Internal class for calling MAPI APIs
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal class MAPIHelperInterop
|
internal class MAPIHelperInterop {
|
||||||
{
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Private constructor.
|
/// Private constructor.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private MAPIHelperInterop()
|
private MAPIHelperInterop() {
|
||||||
{
|
|
||||||
// Intenationally blank
|
// Intenationally blank
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Constructors
|
#endregion Constructors
|
||||||
|
|
||||||
|
|
||||||
#region Structs
|
#region Structs
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||||
public class MapiMessage {
|
public class MapiMessage {
|
||||||
public int Reserved = 0;
|
public int Reserved = 0;
|
||||||
|
@ -491,7 +494,7 @@ namespace Greenshot.Helpers {
|
||||||
public int FileCount = 0;
|
public int FileCount = 0;
|
||||||
public IntPtr Files = IntPtr.Zero;
|
public IntPtr Files = IntPtr.Zero;
|
||||||
}
|
}
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||||
public class MapiRecipDesc {
|
public class MapiRecipDesc {
|
||||||
public int Reserved = 0;
|
public int Reserved = 0;
|
||||||
|
@ -501,263 +504,239 @@ namespace Greenshot.Helpers {
|
||||||
public int eIDSize = 0;
|
public int eIDSize = 0;
|
||||||
public IntPtr EntryID = IntPtr.Zero;
|
public IntPtr EntryID = IntPtr.Zero;
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("MAPI32.DLL", SetLastError = true)]
|
[DllImport("MAPI32.DLL", SetLastError = true)]
|
||||||
public static extern int MAPISendMail(IntPtr session, IntPtr hwnd, MapiMessage message, int flg, int rsv);
|
public static extern int MAPISendMail(IntPtr session, IntPtr hwnd, MapiMessage message, int flg, int rsv);
|
||||||
|
|
||||||
#endregion Structs
|
#endregion Structs
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Private MAPIHelperInterop Class
|
#endregion Private MAPIHelperInterop Class
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Public MapiMailMessage Class
|
#endregion Public MapiMailMessage Class
|
||||||
|
|
||||||
#region Public Recipient Class
|
#region Public Recipient Class
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a Recipient for a MapiMailMessage.
|
/// Represents a Recipient for a MapiMailMessage.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Recipient
|
public class Recipient {
|
||||||
{
|
|
||||||
#region Public Properties
|
#region Public Properties
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The email address of this recipient.
|
/// The email address of this recipient.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Address = null;
|
public string Address = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The display name of this recipient.
|
/// The display name of this recipient.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string DisplayName = null;
|
public string DisplayName = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// How the recipient will receive this message (To, CC, BCC).
|
/// How the recipient will receive this message (To, CC, BCC).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public MapiMailMessage.RecipientType RecipientType = MapiMailMessage.RecipientType.To;
|
public MapiMailMessage.RecipientType RecipientType = MapiMailMessage.RecipientType.To;
|
||||||
|
|
||||||
#endregion Public Properties
|
#endregion Public Properties
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new recipient with the specified address.
|
/// Creates a new recipient with the specified address.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Recipient(string address)
|
public Recipient(string address) {
|
||||||
{
|
|
||||||
Address = address;
|
Address = address;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new recipient with the specified address and display name.
|
/// Creates a new recipient with the specified address and display name.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Recipient(string address, string displayName)
|
public Recipient(string address, string displayName) {
|
||||||
{
|
|
||||||
Address = address;
|
Address = address;
|
||||||
DisplayName = displayName;
|
DisplayName = displayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new recipient with the specified address and recipient type.
|
/// Creates a new recipient with the specified address and recipient type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Recipient(string address, MapiMailMessage.RecipientType recipientType)
|
public Recipient(string address, MapiMailMessage.RecipientType recipientType) {
|
||||||
{
|
|
||||||
Address = address;
|
Address = address;
|
||||||
RecipientType = recipientType;
|
RecipientType = recipientType;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new recipient with the specified address, display name and recipient type.
|
/// Creates a new recipient with the specified address, display name and recipient type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Recipient(string address, string displayName, MapiMailMessage.RecipientType recipientType)
|
public Recipient(string address, string displayName, MapiMailMessage.RecipientType recipientType) {
|
||||||
{
|
|
||||||
Address = address;
|
Address = address;
|
||||||
DisplayName = displayName;
|
DisplayName = displayName;
|
||||||
RecipientType = recipientType;
|
RecipientType = recipientType;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Constructors
|
#endregion Constructors
|
||||||
|
|
||||||
#region Internal Methods
|
#region Internal Methods
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns an interop representation of a recepient.
|
/// Returns an interop representation of a recepient.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
internal MapiMailMessage.MAPIHelperInterop.MapiRecipDesc GetInteropRepresentation()
|
internal MapiMailMessage.MAPIHelperInterop.MapiRecipDesc GetInteropRepresentation() {
|
||||||
{
|
|
||||||
MapiMailMessage.MAPIHelperInterop.MapiRecipDesc interop = new MapiMailMessage.MAPIHelperInterop.MapiRecipDesc();
|
MapiMailMessage.MAPIHelperInterop.MapiRecipDesc interop = new MapiMailMessage.MAPIHelperInterop.MapiRecipDesc();
|
||||||
|
|
||||||
if (DisplayName == null)
|
if (DisplayName == null) {
|
||||||
{
|
|
||||||
interop.Name = Address;
|
interop.Name = Address;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
interop.Name = DisplayName;
|
interop.Name = DisplayName;
|
||||||
interop.Address = Address;
|
interop.Address = Address;
|
||||||
}
|
}
|
||||||
|
|
||||||
interop.RecipientClass = (int)RecipientType;
|
interop.RecipientClass = (int)RecipientType;
|
||||||
|
|
||||||
return interop;
|
return interop;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Internal Methods
|
#endregion Internal Methods
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Public Recipient Class
|
#endregion Public Recipient Class
|
||||||
|
|
||||||
#region Public RecipientCollection Class
|
#region Public RecipientCollection Class
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a colleciton of recipients for a mail message.
|
/// Represents a colleciton of recipients for a mail message.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class RecipientCollection : CollectionBase
|
public class RecipientCollection : CollectionBase {
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds the specified recipient to this collection.
|
/// Adds the specified recipient to this collection.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Add(Recipient value)
|
public void Add(Recipient value) {
|
||||||
{
|
|
||||||
List.Add(value);
|
List.Add(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a new recipient with the specified address to this collection.
|
/// Adds a new recipient with the specified address to this collection.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Add(string address)
|
public void Add(string address) {
|
||||||
{
|
|
||||||
this.Add(new Recipient(address));
|
this.Add(new Recipient(address));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a new recipient with the specified address and display name to this collection.
|
/// Adds a new recipient with the specified address and display name to this collection.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Add(string address, string displayName)
|
public void Add(string address, string displayName) {
|
||||||
{
|
|
||||||
this.Add(new Recipient(address, displayName));
|
this.Add(new Recipient(address, displayName));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a new recipient with the specified address and recipient type to this collection.
|
/// Adds a new recipient with the specified address and recipient type to this collection.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Add(string address, MapiMailMessage.RecipientType recipientType)
|
public void Add(string address, MapiMailMessage.RecipientType recipientType) {
|
||||||
{
|
|
||||||
this.Add(new Recipient(address, recipientType));
|
this.Add(new Recipient(address, recipientType));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a new recipient with the specified address, display name and recipient type to this collection.
|
/// Adds a new recipient with the specified address, display name and recipient type to this collection.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Add(string address, string displayName, MapiMailMessage.RecipientType recipientType)
|
public void Add(string address, string displayName, MapiMailMessage.RecipientType recipientType) {
|
||||||
{
|
|
||||||
this.Add(new Recipient(address, displayName, recipientType));
|
this.Add(new Recipient(address, displayName, recipientType));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the recipient stored in this collection at the specified index.
|
/// Returns the recipient stored in this collection at the specified index.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Recipient this[int index]
|
public Recipient this[int index] {
|
||||||
{
|
get {
|
||||||
get
|
|
||||||
{
|
|
||||||
return (Recipient)List[index];
|
return (Recipient)List[index];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal InteropRecipientCollection GetInteropRepresentation()
|
internal InteropRecipientCollection GetInteropRepresentation() {
|
||||||
{
|
|
||||||
return new InteropRecipientCollection(this);
|
return new InteropRecipientCollection(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Struct which contains an interop representation of a colleciton of recipients.
|
/// Struct which contains an interop representation of a colleciton of recipients.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal struct InteropRecipientCollection : IDisposable
|
internal struct InteropRecipientCollection : IDisposable {
|
||||||
{
|
|
||||||
#region Member Variables
|
#region Member Variables
|
||||||
|
|
||||||
private IntPtr _handle;
|
private IntPtr _handle;
|
||||||
private int _count;
|
private int _count;
|
||||||
|
|
||||||
#endregion Member Variables
|
#endregion Member Variables
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Default constructor for creating InteropRecipientCollection.
|
/// Default constructor for creating InteropRecipientCollection.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="outer"></param>
|
/// <param name="outer"></param>
|
||||||
public InteropRecipientCollection(RecipientCollection outer)
|
public InteropRecipientCollection(RecipientCollection outer) {
|
||||||
{
|
|
||||||
_count = outer.Count;
|
_count = outer.Count;
|
||||||
|
|
||||||
if (_count == 0)
|
if (_count == 0) {
|
||||||
{
|
|
||||||
_handle = IntPtr.Zero;
|
_handle = IntPtr.Zero;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// allocate enough memory to hold all recipients
|
// allocate enough memory to hold all recipients
|
||||||
int size = Marshal.SizeOf(typeof(MapiMailMessage.MAPIHelperInterop.MapiRecipDesc));
|
int size = Marshal.SizeOf(typeof(MapiMailMessage.MAPIHelperInterop.MapiRecipDesc));
|
||||||
_handle = Marshal.AllocHGlobal(_count * size);
|
_handle = Marshal.AllocHGlobal(_count * size);
|
||||||
|
|
||||||
// place all interop recipients into the memory just allocated
|
// place all interop recipients into the memory just allocated
|
||||||
int ptr = (int)_handle;
|
int ptr = (int)_handle;
|
||||||
foreach (Recipient native in outer)
|
foreach (Recipient native in outer) {
|
||||||
{
|
|
||||||
MapiMailMessage.MAPIHelperInterop.MapiRecipDesc interop = native.GetInteropRepresentation();
|
MapiMailMessage.MAPIHelperInterop.MapiRecipDesc interop = native.GetInteropRepresentation();
|
||||||
|
|
||||||
// stick it in the memory block
|
// stick it in the memory block
|
||||||
Marshal.StructureToPtr(interop, (IntPtr)ptr, false);
|
Marshal.StructureToPtr(interop, (IntPtr)ptr, false);
|
||||||
ptr += size;
|
ptr += size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Costructors
|
#endregion Costructors
|
||||||
|
|
||||||
#region Public Properties
|
#region Public Properties
|
||||||
|
|
||||||
public IntPtr Handle
|
public IntPtr Handle {
|
||||||
{
|
get {
|
||||||
get { return _handle; }
|
return _handle;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Public Properties
|
#endregion Public Properties
|
||||||
|
|
||||||
#region Public Methods
|
#region Public Methods
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Disposes of resources.
|
/// Disposes of resources.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Dispose()
|
public void Dispose() {
|
||||||
{
|
if (_handle != IntPtr.Zero) {
|
||||||
if (_handle != IntPtr.Zero)
|
|
||||||
{
|
|
||||||
Type type = typeof(MapiMailMessage.MAPIHelperInterop.MapiRecipDesc);
|
Type type = typeof(MapiMailMessage.MAPIHelperInterop.MapiRecipDesc);
|
||||||
int size = Marshal.SizeOf(type);
|
int size = Marshal.SizeOf(type);
|
||||||
|
|
||||||
// destroy all the structures in the memory area
|
// destroy all the structures in the memory area
|
||||||
int ptr = (int)_handle;
|
int ptr = (int)_handle;
|
||||||
for (int i = 0; i < _count; i++)
|
for (int i = 0; i < _count; i++) {
|
||||||
{
|
|
||||||
Marshal.DestroyStructure((IntPtr)ptr, type);
|
Marshal.DestroyStructure((IntPtr)ptr, type);
|
||||||
ptr += size;
|
ptr += size;
|
||||||
}
|
}
|
||||||
|
|
||||||
// free the memory
|
// free the memory
|
||||||
Marshal.FreeHGlobal(_handle);
|
Marshal.FreeHGlobal(_handle);
|
||||||
|
|
||||||
_handle = IntPtr.Zero;
|
_handle = IntPtr.Zero;
|
||||||
_count = 0;
|
_count = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Public Methods
|
#endregion Public Methods
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Public RecipientCollection Class
|
#endregion Public RecipientCollection Class
|
||||||
}
|
}
|
|
@ -44,6 +44,7 @@ Bugs resolved (for bug details go to http://sourceforge.net/p/greenshot/bugs and
|
||||||
* Not reported: When first selecting a printer, the main printer destination has been replaced by the selected one, making the Windows printer dialog unavailable for further prints
|
* Not reported: When first selecting a printer, the main printer destination has been replaced by the selected one, making the Windows printer dialog unavailable for further prints
|
||||||
* Not reported: Open last capture in explorer doesn't open the right location
|
* Not reported: Open last capture in explorer doesn't open the right location
|
||||||
* Not reported: Fixed some issues where the sub-menus of the context menu moved to the next screen.
|
* Not reported: Fixed some issues where the sub-menus of the context menu moved to the next screen.
|
||||||
|
* Not reported: When having Outlook installed but not the Office plugin there was no EMail destination.
|
||||||
|
|
||||||
Known issues:
|
Known issues:
|
||||||
* Greenshot general: a captured I-Beam cursor isn't displayed correctly on the final result.
|
* Greenshot general: a captured I-Beam cursor isn't displayed correctly on the final result.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue