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:
RKrom 2013-02-14 08:15:11 +00:00
commit 2b4df68c1f
2 changed files with 160 additions and 180 deletions

View file

@ -61,7 +61,7 @@ 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();
@ -173,30 +173,42 @@ namespace Greenshot.Helpers {
/// 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
@ -273,18 +285,15 @@ namespace Greenshot.Helpers {
/// 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;
} }
@ -298,15 +307,12 @@ namespace Greenshot.Helpers {
/// </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;
} }
@ -317,8 +323,7 @@ namespace Greenshot.Helpers {
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;
@ -459,15 +464,13 @@ namespace Greenshot.Helpers {
/// <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
} }
@ -518,8 +521,7 @@ namespace Greenshot.Helpers {
/// <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>
@ -544,16 +546,14 @@ namespace Greenshot.Helpers {
/// <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;
} }
@ -561,8 +561,7 @@ namespace Greenshot.Helpers {
/// <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;
} }
@ -570,8 +569,7 @@ namespace Greenshot.Helpers {
/// <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;
@ -585,16 +583,12 @@ namespace Greenshot.Helpers {
/// 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;
} }
@ -614,69 +608,59 @@ namespace Greenshot.Helpers {
/// <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;
@ -690,12 +674,10 @@ namespace Greenshot.Helpers {
/// 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;
} }
@ -706,8 +688,7 @@ namespace Greenshot.Helpers {
// 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
@ -720,9 +701,10 @@ namespace Greenshot.Helpers {
#region Public Properties #region Public Properties
public IntPtr Handle public IntPtr Handle {
{ get {
get { return _handle; } return _handle;
}
} }
#endregion Public Properties #endregion Public Properties
@ -732,17 +714,14 @@ namespace Greenshot.Helpers {
/// <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;
} }

View file

@ -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.