Skip to content

Commit

Permalink
discharge unsaved attachments in signed emails
Browse files Browse the repository at this point in the history
  • Loading branch information
ahaenggli committed Aug 26, 2020
1 parent 2cc39c7 commit cf73c18
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 59 deletions.
2 changes: 1 addition & 1 deletion OutlookAddIn_KeepAttachmentsOnReply.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<PublishUrl>\\asyn\web\PlugIn\outlook\</PublishUrl>
<InstallUrl />
<TargetCulture>de</TargetCulture>
<ApplicationVersion>1.0.6.1</ApplicationVersion>
<ApplicationVersion>1.0.6.2</ApplicationVersion>
<AutoIncrementApplicationRevision>true</AutoIncrementApplicationRevision>
<UpdateEnabled>true</UpdateEnabled>
<UpdateInterval>0</UpdateInterval>
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.6.0")]
[assembly: AssemblyFileVersion("1.0.6.0")]
[assembly: AssemblyVersion("1.0.6.1")]
[assembly: AssemblyFileVersion("1.0.6.1")]

27 changes: 13 additions & 14 deletions Ribbon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,27 @@ public class Ribbon : Office.IRibbonExtensibility

private Office.IRibbonUI ribbon;

private void getAttachmentsFromConversation(MailItem dest, MailItem search)
private void getAttachmentsFromConversation(MailItem mailItem)
{
if (dest == null)
if (mailItem == null)
{
return;
}

if (dest.Attachments.CountNonEmbeddedAttachments() > 0)
if (mailItem.Attachments.CountNonEmbeddedAttachments() > 0)
{
return;
}


System.Collections.Generic.Stack<MailItem> st = new System.Collections.Generic.Stack<MailItem>();

// Cast selectedItem to MailItem.

// Determine the store of the mail item.
Outlook.Folder folder = search.Parent as Outlook.Folder;
Outlook.Folder folder = mailItem.Parent as Outlook.Folder;
Outlook.Store store = folder.Store;
if (store.IsConversationEnabled == true)
{
// Obtain a Conversation object.
Outlook.Conversation conv = search.GetConversation();
Outlook.Conversation conv = mailItem.GetConversation();
// Check for null Conversation.
if (conv != null)
{
Expand Down Expand Up @@ -88,19 +85,21 @@ private void getAttachmentsFromConversation(MailItem dest, MailItem search)

try
{
ThisAddIn.addParentAttachments(dest, it);
dest.Save();
ThisAddIn.addParentAttachments(mailItem, it);
mailItem.Save();
}
catch {
if(mailItem.IsMailItemSignedOrEncrypted())
mailItem.Close(OlInspectorClose.olDiscard);
}
catch { }

st.Clear();
}
}

st.Clear();
}



private void EnumerateConversation(System.Collections.Generic.Stack<MailItem> st, object item, Outlook.Conversation conversation)
{
Outlook.SimpleItems items =
Expand Down Expand Up @@ -162,7 +161,7 @@ public void OnFindMissingAttachments(Office.IRibbonControl e)
}

//if (mailitem.Attachments.Count > 0) return;
getAttachmentsFromConversation(mailItem, mailItem);
getAttachmentsFromConversation(mailItem);
}

}
Expand Down
79 changes: 37 additions & 42 deletions ThisAddIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,57 +78,52 @@ private void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector
/// </summary>
private void parseItem(object item)
{
if (item == null) return;

// is it a mail?
if (item is Outlook.MailItem)
{
// cast to MailItem
MailItem mailItem = item as MailItem;
if (!(item is Outlook.MailItem)) return;

// item not NULL
if (mailItem != null)
// cast to MailItem
MailItem mailItem = item as MailItem;
if (mailItem == null) return;

// it is a new one
if (mailItem.EntryID == null && mailItem.Sent == false)
{
// is it a reply?
bool isReply = !string.IsNullOrEmpty(mailItem.To) || mailItem.Recipients.Count > 0;
// it is!
if (isReply)
{
// it is a new one
if (mailItem.EntryID == null && mailItem.Sent == false)
// keep attachments from original mail
// get selected item (reply is open, so this should be the original mail)
MailItem src = null;
if (app.ActiveWindow() is Outlook.Explorer)
{
// is it a reply?
bool isReply = !string.IsNullOrEmpty(mailItem.To) || mailItem.Recipients.Count > 0;
// it is!
if (isReply)
//Debug.WriteLine("Explorer");
if (Application.ActiveExplorer().Selection.Count == 1)
{
// keep attachments from original mail
// get selected item (reply is open, so this should be the original mail)
MailItem src = null;
if (app.ActiveWindow() is Outlook.Explorer)
object selectedItem = Application.ActiveExplorer().Selection[1];
if (selectedItem is Outlook.MailItem)
{
//Debug.WriteLine("Explorer");

if (Application.ActiveExplorer().Selection.Count == 1)
{
object selectedItem = Application.ActiveExplorer().Selection[1];
if (selectedItem is Outlook.MailItem)
{
src = selectedItem as Outlook.MailItem;
}
}
}
else
if (app.ActiveWindow() is Outlook.Inspector)
{
//Debug.WriteLine("Inspector");

object selectedItem = Application.ActiveInspector().CurrentItem;
if (selectedItem is Outlook.MailItem)
{
src = selectedItem as Outlook.MailItem;
}

src = selectedItem as Outlook.MailItem;
}

if (src != null)
addParentAttachments(mailItem, src);

}
}
else
if (app.ActiveWindow() is Outlook.Inspector)
{
//Debug.WriteLine("Inspector");
object selectedItem = Application.ActiveInspector().CurrentItem;
if (selectedItem is Outlook.MailItem)
{
src = selectedItem as Outlook.MailItem;
}
}

if (src != null)
addParentAttachments(mailItem, src);

}
}
}
Expand Down

0 comments on commit cf73c18

Please sign in to comment.