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
parent 442a978d13
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)) {
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.ShowDialog();
@ -173,30 +173,42 @@ namespace Greenshot.Helpers {
/// Gets or sets the subject of this mail message.
/// </summary>
public string Subject {
get { return _subject; }
set { _subject = value; }
get {
return _subject;
}
set {
_subject = value;
}
}
/// <summary>
/// Gets or sets the body of this mail message.
/// </summary>
public string Body {
get { return _body; }
set { _body = value; }
get {
return _body;
}
set {
_body = value;
}
}
/// <summary>
/// Gets the recipient list for this mail message.
/// </summary>
public RecipientCollection Recipients {
get { return _recipientCollection; }
get {
return _recipientCollection;
}
}
/// <summary>
/// Gets the file list for this mail message.
/// </summary>
public List<string> Files {
get { return _files; }
get {
return _files;
}
}
#endregion Public Properties
@ -273,18 +285,15 @@ namespace Greenshot.Helpers {
/// Deallocates the files in a message.
/// </summary>
/// <param name="message">The message to deallocate the files from.</param>
private void _DeallocFiles(MAPIHelperInterop.MapiMessage message)
{
if (message.Files != IntPtr.Zero)
{
private void _DeallocFiles(MAPIHelperInterop.MapiMessage message) {
if (message.Files != IntPtr.Zero) {
Type fileDescType = typeof(MapiFileDescriptor);
int fsize = Marshal.SizeOf(fileDescType);
// Get the ptr to the files
int runptr = (int)message.Files;
// Release each file
for (int i = 0; i < message.FileCount; i++)
{
for (int i = 0; i < message.FileCount; i++) {
Marshal.DestroyStructure((IntPtr)runptr, fileDescType);
runptr += fsize;
}
@ -298,15 +307,12 @@ namespace Greenshot.Helpers {
/// </summary>
/// <param name="fileCount"></param>
/// <returns></returns>
private IntPtr _AllocAttachments(out int fileCount)
{
private IntPtr _AllocAttachments(out int fileCount) {
fileCount = 0;
if (_files == null)
{
if (_files == null) {
return IntPtr.Zero;
}
if ((_files.Count <= 0) || (_files.Count > 100))
{
if ((_files.Count <= 0) || (_files.Count > 100)) {
return IntPtr.Zero;
}
@ -317,8 +323,7 @@ namespace Greenshot.Helpers {
MapiFileDescriptor mfd = new MapiFileDescriptor();
mfd.position = -1;
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;
mfd.name = Path.GetFileName(path);
mfd.path = path;
@ -459,15 +464,13 @@ namespace Greenshot.Helpers {
/// <summary>
/// Internal class for calling MAPI APIs
/// </summary>
internal class MAPIHelperInterop
{
internal class MAPIHelperInterop {
#region Constructors
/// <summary>
/// Private constructor.
/// </summary>
private MAPIHelperInterop()
{
private MAPIHelperInterop() {
// Intenationally blank
}
@ -518,8 +521,7 @@ namespace Greenshot.Helpers {
/// <summary>
/// Represents a Recipient for a MapiMailMessage.
/// </summary>
public class Recipient
{
public class Recipient {
#region Public Properties
/// <summary>
@ -544,16 +546,14 @@ namespace Greenshot.Helpers {
/// <summary>
/// Creates a new recipient with the specified address.
/// </summary>
public Recipient(string address)
{
public Recipient(string address) {
Address = address;
}
/// <summary>
/// Creates a new recipient with the specified address and display name.
/// </summary>
public Recipient(string address, string displayName)
{
public Recipient(string address, string displayName) {
Address = address;
DisplayName = displayName;
}
@ -561,8 +561,7 @@ namespace Greenshot.Helpers {
/// <summary>
/// Creates a new recipient with the specified address and recipient type.
/// </summary>
public Recipient(string address, MapiMailMessage.RecipientType recipientType)
{
public Recipient(string address, MapiMailMessage.RecipientType recipientType) {
Address = address;
RecipientType = recipientType;
}
@ -570,8 +569,7 @@ namespace Greenshot.Helpers {
/// <summary>
/// Creates a new recipient with the specified address, display name and recipient type.
/// </summary>
public Recipient(string address, string displayName, MapiMailMessage.RecipientType recipientType)
{
public Recipient(string address, string displayName, MapiMailMessage.RecipientType recipientType) {
Address = address;
DisplayName = displayName;
RecipientType = recipientType;
@ -585,16 +583,12 @@ namespace Greenshot.Helpers {
/// Returns an interop representation of a recepient.
/// </summary>
/// <returns></returns>
internal MapiMailMessage.MAPIHelperInterop.MapiRecipDesc GetInteropRepresentation()
{
internal MapiMailMessage.MAPIHelperInterop.MapiRecipDesc GetInteropRepresentation() {
MapiMailMessage.MAPIHelperInterop.MapiRecipDesc interop = new MapiMailMessage.MAPIHelperInterop.MapiRecipDesc();
if (DisplayName == null)
{
if (DisplayName == null) {
interop.Name = Address;
}
else
{
} else {
interop.Name = DisplayName;
interop.Address = Address;
}
@ -614,69 +608,59 @@ namespace Greenshot.Helpers {
/// <summary>
/// Represents a colleciton of recipients for a mail message.
/// </summary>
public class RecipientCollection : CollectionBase
{
public class RecipientCollection : CollectionBase {
/// <summary>
/// Adds the specified recipient to this collection.
/// </summary>
public void Add(Recipient value)
{
public void Add(Recipient value) {
List.Add(value);
}
/// <summary>
/// Adds a new recipient with the specified address to this collection.
/// </summary>
public void Add(string address)
{
public void Add(string address) {
this.Add(new Recipient(address));
}
/// <summary>
/// Adds a new recipient with the specified address and display name to this collection.
/// </summary>
public void Add(string address, string displayName)
{
public void Add(string address, string displayName) {
this.Add(new Recipient(address, displayName));
}
/// <summary>
/// Adds a new recipient with the specified address and recipient type to this collection.
/// </summary>
public void Add(string address, MapiMailMessage.RecipientType recipientType)
{
public void Add(string address, MapiMailMessage.RecipientType recipientType) {
this.Add(new Recipient(address, recipientType));
}
/// <summary>
/// Adds a new recipient with the specified address, display name and recipient type to this collection.
/// </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));
}
/// <summary>
/// Returns the recipient stored in this collection at the specified index.
/// </summary>
public Recipient this[int index]
{
get
{
public Recipient this[int index] {
get {
return (Recipient)List[index];
}
}
internal InteropRecipientCollection GetInteropRepresentation()
{
internal InteropRecipientCollection GetInteropRepresentation() {
return new InteropRecipientCollection(this);
}
/// <summary>
/// Struct which contains an interop representation of a colleciton of recipients.
/// </summary>
internal struct InteropRecipientCollection : IDisposable
{
internal struct InteropRecipientCollection : IDisposable {
#region Member Variables
private IntPtr _handle;
@ -690,12 +674,10 @@ namespace Greenshot.Helpers {
/// Default constructor for creating InteropRecipientCollection.
/// </summary>
/// <param name="outer"></param>
public InteropRecipientCollection(RecipientCollection outer)
{
public InteropRecipientCollection(RecipientCollection outer) {
_count = outer.Count;
if (_count == 0)
{
if (_count == 0) {
_handle = IntPtr.Zero;
return;
}
@ -706,8 +688,7 @@ namespace Greenshot.Helpers {
// place all interop recipients into the memory just allocated
int ptr = (int)_handle;
foreach (Recipient native in outer)
{
foreach (Recipient native in outer) {
MapiMailMessage.MAPIHelperInterop.MapiRecipDesc interop = native.GetInteropRepresentation();
// stick it in the memory block
@ -720,9 +701,10 @@ namespace Greenshot.Helpers {
#region Public Properties
public IntPtr Handle
{
get { return _handle; }
public IntPtr Handle {
get {
return _handle;
}
}
#endregion Public Properties
@ -732,17 +714,14 @@ namespace Greenshot.Helpers {
/// <summary>
/// Disposes of resources.
/// </summary>
public void Dispose()
{
if (_handle != IntPtr.Zero)
{
public void Dispose() {
if (_handle != IntPtr.Zero) {
Type type = typeof(MapiMailMessage.MAPIHelperInterop.MapiRecipDesc);
int size = Marshal.SizeOf(type);
// destroy all the structures in the memory area
int ptr = (int)_handle;
for (int i = 0; i < _count; i++)
{
for (int i = 0; i < _count; i++) {
Marshal.DestroyStructure((IntPtr)ptr, type);
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: 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: When having Outlook installed but not the Office plugin there was no EMail destination.
Known issues:
* Greenshot general: a captured I-Beam cursor isn't displayed correctly on the final result.