--- a/CryptableMailItem.cs Mon Jul 16 17:01:23 2018 +0200
+++ b/CryptableMailItem.cs Fri Jul 20 13:21:53 2018 +0200
@@ -1480,7 +1480,8 @@
* which then leads to the form region not being properly displayed at the first click (OUT-68).
*/
if ((isPEPInternal == false) &&
- (Globals.OutlookVersion == Globals.Version.Outlook2010 && (this.internalMailItem.GetIsInSecureStore() || this.internalMailItem.DownloadState == Outlook.OlDownloadState.olHeaderOnly)))
+ ((Globals.OutlookVersion == Globals.Version.Outlook2010) &&
+ (this.internalMailItem.GetIsInSecureStore() || this.internalMailItem.GetNeverUnsecure())))
{
try
{
--- a/Extensions/MailItemExtensions.cs Mon Jul 16 17:01:23 2018 +0200
+++ b/Extensions/MailItemExtensions.cs Fri Jul 20 13:21:53 2018 +0200
@@ -2214,11 +2214,11 @@
/// Gets the outgoing rating for this mail item.
/// </summary>
/// <param name="omi">The Outlook mail item to process with.</param>
- /// <param name="ignoreForceUnencrypted">Do not return 'Unencrypted' if the ForceUnencrypted
- /// property is set, but rather return the message's rating as if it wasn't set.</param>
+ /// <param name="ignoreOptions">Ignore user settings like ForceProtection or
+ /// ForceUnencrypted and return always calculated engine rating.</param>
/// <returns>The outgoing rating for the mail item.</returns>
public static pEpRating GetOutgoingRating(this Outlook.MailItem omi,
- bool ignoreForceUnencrypted = false)
+ bool ignoreOptions = false)
{
pEpRating rating = pEpRating.pEpRatingUndefined;
@@ -2244,24 +2244,33 @@
return pEpRating.pEpRatingUnencrypted;
}
- // If mail is forcefully protected, return reliable
- if (omi?.GetIsForcefullyProtected() == true)
+ // If pEp is disabled, return unencrypted
+ if ((omi?.GetIsPEPEnabled() == false) &&
+ (omi.GetEnableProtection() == false))
{
- return pEpRating.pEpRatingReliable;
+ return pEpRating.pEpRatingUnencrypted;
}
- // If mail is forcefully unencrypted, return unencrypted
- if ((omi?.GetIsForceUnencrypted() == true) &&
- (ignoreForceUnencrypted == false))
+ if (ignoreOptions == false)
{
- return pEpRating.pEpRatingUnencrypted;
+ /* If message is forcefully unencrypted, return Unencrypted.
+ * If message is forcefully encrypted, return Reliable.
+ */
+ if (omi?.GetIsForcefullyProtected() == true)
+ {
+ return pEpRating.pEpRatingReliable;
+ }
+ else if (omi?.GetIsForceUnencrypted() == true)
+ {
+ return pEpRating.pEpRatingUnencrypted;
+ }
}
// Else calculate it
PEPMessage message;
if (PEPMessage.Create(omi, out message, true, false) == Globals.ReturnStatus.Success)
{
- rating = message?.GetOutgoingRating(ignoreForceUnencrypted) ?? pEpRating.pEpRatingUndefined;
+ rating = message?.GetOutgoingRating(ignoreOptions) ?? pEpRating.pEpRatingUndefined;
}
else
{
--- a/PEPMessage.cs Mon Jul 16 17:01:23 2018 +0200
+++ b/PEPMessage.cs Fri Jul 20 13:21:53 2018 +0200
@@ -450,47 +450,53 @@
/// <summary>
/// Gets the outgoing rating of this message.
- /// <param name="ignoreForceUnencrypted">Do not return 'Unencrypted' if the ForceUnencrypted
- /// property is set, but rather return the message's rating as if it wasn't set.</param>
+ /// <param name="ignoreOptions">Ignore user settings like ForceProtection or
+ /// ForceUnencrypted and return always calculated engine rating.</param>
/// </summary>
- public pEpRating GetOutgoingRating(bool ignoreForceUnencrypted = false)
+ public pEpRating GetOutgoingRating(bool ignoreOptions = false)
{
pEpRating rating = pEpRating.pEpRatingUndefined;
#if READER_RELEASE_MODE
- // If reader mode, always unencrypted
- rating = pEpRating.pEpRatingUnencrypted;
+ // If reader mode, always unencrypted
+ rating = pEpRating.pEpRatingUnencrypted;
#else
- /* If message is forcefully unencrypted or has BCC recipients,
- * always return Unencrypted.
- * If message is forcefully encrypted, return Reliable.
- * Else, calculate through engine.
- */
- if (((this.ForceUnencrypted) && (ignoreForceUnencrypted == false)) ||
- (this.Bcc?.Count > 0))
+ // If message has BCC recipients, always return unencrypted
+ if (this.Bcc?.Count > 0)
{
- rating = pEpRating.pEpRatingUnencrypted;
+ return pEpRating.pEpRatingUnencrypted;
}
- else if (string.IsNullOrEmpty(this.ForceProtectionId) == false)
+
+ if (ignoreOptions == false)
{
- rating = pEpRating.pEpRatingReliable;
- }
- else
- {
- PEPMessage workingMessage = this.Copy(true);
- workingMessage.FlattenAllRecipientIdentities();
- workingMessage.Direction = pEpMsgDirection.pEpDirOutgoing;
-
- try
+ /* If message is forcefully unencrypted, return Unencrypted.
+ * If message is forcefully encrypted, return Reliable.
+ */
+ if (this.ForceUnencrypted)
{
- rating = ThisAddIn.PEPEngine.OutgoingMessageRating(workingMessage.ToCOMType());
+ return pEpRating.pEpRatingUnencrypted;
}
- catch (Exception ex)
+ else if (string.IsNullOrEmpty(this.ForceProtectionId) == false)
{
- rating = pEpRating.pEpRatingUndefined;
- Log.Error("GetOutgoingRating: Error getting outgoing rating from engine. " + ex.ToString());
+ return pEpRating.pEpRatingReliable;
}
}
+
+ // If we have no rating at this point, calculate it
+ PEPMessage workingMessage = this.Copy(true);
+ workingMessage.FlattenAllRecipientIdentities();
+ workingMessage.Direction = pEpMsgDirection.pEpDirOutgoing;
+
+ try
+ {
+ rating = ThisAddIn.PEPEngine.OutgoingMessageRating(workingMessage.ToCOMType());
+ }
+ catch (Exception ex)
+ {
+ rating = pEpRating.pEpRatingUndefined;
+ Log.Error("GetOutgoingRating: Error getting outgoing rating from engine. " + ex.ToString());
+ }
+
#endif
return rating;
}
--- a/UI/FormRegionPrivacyStatus.Designer.cs Mon Jul 16 17:01:23 2018 +0200
+++ b/UI/FormRegionPrivacyStatus.Designer.cs Fri Jul 20 13:21:53 2018 +0200
@@ -43,41 +43,25 @@
{
this.components = new System.ComponentModel.Container();
this.TimerRefresh = new System.Windows.Forms.Timer(this.components);
- this.PanelPrivacyStatus = new System.Windows.Forms.Panel();
this.ElementHostFormControl = new System.Windows.Forms.Integration.ElementHost();
- this.FormControlPrivacyStatusChild = new pEp.UI.FormControlPrivacyStatus();
- this.PanelPrivacyStatus.SuspendLayout();
this.SuspendLayout();
//
- // PanelPrivacyStatus
- //
- this.PanelPrivacyStatus.BackColor = System.Drawing.Color.Transparent;
- this.PanelPrivacyStatus.Controls.Add(this.ElementHostFormControl);
- this.PanelPrivacyStatus.Dock = System.Windows.Forms.DockStyle.Fill;
- this.PanelPrivacyStatus.Location = new System.Drawing.Point(0, 0);
- this.PanelPrivacyStatus.Name = "PanelPrivacyStatus";
- this.PanelPrivacyStatus.Size = new System.Drawing.Size(500, 36);
- this.PanelPrivacyStatus.TabIndex = 0;
- //
// ElementHostFormControl
//
- this.ElementHostFormControl.Dock = System.Windows.Forms.DockStyle.Fill;
this.ElementHostFormControl.Location = new System.Drawing.Point(0, 0);
this.ElementHostFormControl.Name = "ElementHostFormControl";
- this.ElementHostFormControl.Size = new System.Drawing.Size(500, 36);
+ this.ElementHostFormControl.Size = new System.Drawing.Size(200, 100);
this.ElementHostFormControl.TabIndex = 0;
- this.ElementHostFormControl.Child = this.FormControlPrivacyStatusChild;
+ this.ElementHostFormControl.Child = null;
//
// FormRegionPrivacyStatus
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.Controls.Add(this.PanelPrivacyStatus);
this.Name = "FormRegionPrivacyStatus";
this.Size = new System.Drawing.Size(500, 36);
this.FormRegionShowing += new System.EventHandler(this.FormRegionPrivacyStatus_FormRegionShowing);
this.FormRegionClosed += new System.EventHandler(this.FormRegionPrivacyStatus_FormRegionClosed);
- this.PanelPrivacyStatus.ResumeLayout(false);
this.ResumeLayout(false);
}
@@ -101,9 +85,7 @@
#endregion
private System.Windows.Forms.Timer TimerRefresh;
- private System.Windows.Forms.Panel PanelPrivacyStatus;
private System.Windows.Forms.Integration.ElementHost ElementHostFormControl;
- private UI.FormControlPrivacyStatus FormControlPrivacyStatusChild;
public partial class FormRegionPrivacyStatusFactory : Microsoft.Office.Tools.Outlook.IFormRegionFactory
{
--- a/UI/FormRegionPrivacyStatus.cs Mon Jul 16 17:01:23 2018 +0200
+++ b/UI/FormRegionPrivacyStatus.cs Fri Jul 20 13:21:53 2018 +0200
@@ -94,15 +94,12 @@
private bool isEnabled = true;
private bool isManagerFormEnabled = true;
private bool isStarted = false;
- private FormManagePrivacyStatus managerForm = null;
private bool processingOngoing = false;
private bool refreshOngoing = false;
private bool repeatProcessing = false;
private int repeatCounter = 0;
private const int maxRepeatCount = 5;
- private MailItemProperties omiProperties = new MailItemProperties();
-
/**************************************************************
*
* Property Accessors
@@ -110,23 +107,46 @@
*************************************************************/
/// <summary>
- /// Gets or sets the displayed state.
+ /// The rating of this message.
+ /// </summary>
+ private pEpRating _Rating = pEpRating.pEpRatingUndefined;
+
+ /// <summary>
+ /// Gets or sets whether to disable the Force Protection option.
+ /// </summary>
+ public bool DisableForceProtection { get; set; } = false;
+
+ /// <summary>
+ /// Gets or sets whether to send this message forcefully protected.
/// </summary>
- public FormControlPrivacyStatus.State DisplayState
+ public bool ForceProtection { get; set; } = false;
+
+ /// <summary>
+ /// Gets or sets whether to send this message forcefully unencrypted.
+ /// </summary>
+ public bool ForceUnencrypted { get; set; } = false;
+
+ /// <summary>
+ /// Gets or sets whether to always store this message as if on an untrusted server.
+ /// </summary>
+ public bool NeverUnsecure { get; set; } = false;
+
+ /// <summary>
+ /// Gets the rating of this message.
+ /// </summary>
+ public pEpRating Rating
{
- get { return (this.FormControlPrivacyStatusChild.DisplayState); }
- set { this.FormControlPrivacyStatusChild.DisplayState = value; }
+ get { return this._Rating; }
}
/// <summary>
- /// Gets the outgoing rating or the last calculated rating of the form region's mail item.
+ /// Sets the rating of this message and updates the UI.
/// </summary>
- public pEpRating Rating
+ /// <param name="rating">The message rating.</param>
+ public void SetRating(pEpRating rating)
{
- get
- {
- return this.omiProperties.Rating;
- }
+ this._Rating = rating;
+ RibbonCustomizations.Invalidate();
}
/**************************************************************
@@ -158,21 +178,37 @@
}
// Build the dialog
+ Outlook.MailItem omi = null;
try
{
+ // Get the Outlook mail item
+ omi = this.OutlookItem as Outlook.MailItem;
+
// The PEPMessage to build the dialog with
PEPMessage message = null;
// If message is a draft, create it directly from the Outlook mail item
- if ((this.OutlookItem as Outlook.MailItem)?.GetIsDraft() == true)
+ if (omi?.GetIsDraft() == true)
{
Log.Verbose("BuildAndShowManager: Creating PEPMessage from draft.");
- if (PEPMessage.Create((this.OutlookItem as Outlook.MailItem), out message) != Globals.ReturnStatus.Success)
+ if (PEPMessage.Create(omi, out message) != Globals.ReturnStatus.Success)
{
Log.Error("BuildAndShowManager: Error creating PEPMessage from draft.");
message = null;
}
+
+ // If Force Protection is set, assign a random GUID
+ if ((this.ForceProtection) &&
+ (this.DisableForceProtection == false))
+ {
+ message.ForceProtectionId = Guid.NewGuid().ToString();
+ }
+
+ // If message is Force Unencrypted, assign it
+ message.ForceUnencrypted = this.ForceUnencrypted;
+
+ omi = null;
}
else
{
@@ -185,13 +221,10 @@
{
Log.Verbose("BuildAndShowManager: Using fallback method to get message.");
- Outlook.MailItem omi = null;
Outlook.MailItem mirror = null;
try
{
- omi = this.OutlookItem as Outlook.MailItem;
-
// For securely stored mails, try to look up mirror
if (omi?.GetIsSecurelyStored() == true)
{
@@ -257,7 +290,6 @@
// Build dialog
if (message != null)
{
- message.Rating = AdapterExtensions.ReevaluateMessageRating(message);
handshakeDialog = new HandshakeDialog(message, this.cryptableMailItem.Myself, this.cryptableMailItem.IsDraft);
handshakeDialog.OnUpdateStatus += HandshakeDialog_Updated;
handshakeDialog.Closed += HandshakeDialog_Closed;
@@ -272,6 +304,10 @@
{
Globals.StopAndSendCrashReport(ex);
}
+ finally
+ {
+ omi = null;
+ }
}
/// <summary>
@@ -321,7 +357,6 @@
{
this.ResolveAllRecipients();
this.RequestRatingAndUIUpdate();
- RibbonCustomizations.Invalidate();
}
}
@@ -372,7 +407,7 @@
}
else
{
- tempFolder = store.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderDrafts) as Outlook.Folder;
+ tempFolder = store.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderDrafts) as Outlook.Folder;
}
if (tempFolder != null)
@@ -422,35 +457,11 @@
}
finally
{
- if (application != null)
- {
- //Marshal.ReleaseComObject(application);
- application = null;
- }
-
- if (currentInspector != null)
- {
- // Marshal.ReleaseComObject(currentInspector);
- currentInspector = null;
- }
-
- if (newInspector != null)
- {
- // Marshal.ReleaseComObject(newInspector);
- newInspector = null;
- }
-
- if (tempMailItem != null)
- {
- // Marshal.ReleaseComObject(tempMailItem);
- tempMailItem = null;
- }
-
- if (omi != null)
- {
- // Marshal.ReleaseComObject(omi);
- omi = null;
- }
+ application = null;
+ currentInspector = null;
+ newInspector = null;
+ omi = null;
+ tempMailItem = null;
}
}
@@ -458,16 +469,6 @@
}
/// <summary>
- /// Sets the rating of the privacy status button.
- /// </summary>
- /// <param name="rating">The rating to set.</param>
- public void SetRating(pEpRating rating)
- {
- this.omiProperties.Rating = rating;
- RibbonCustomizations.Invalidate();
- }
-
- /// <summary>
/// Clears the associated unencrypted preview and displays the given note (if any).
/// </summary>
/// <param name="note">The note to diplsay.</param>
@@ -565,7 +566,10 @@
}
}
}
- catch { }
+ catch (Exception ex)
+ {
+ Log.Error("SetIsEnabled: Error occured. " + ex.ToString());
+ }
finally
{
currAccount = null;
@@ -575,18 +579,6 @@
sendingAccount = null;
}
- // Set reader upgrade link visibility
- if ((Globals.RELEASE_MODE == Globals.ReleaseMode.Reader) &&
- (this.cryptableMailItem != null) &&
- (this.cryptableMailItem.IsDraft))
- {
- this.FormControlPrivacyStatusChild.DisplayState.UpgradeLinkIsVisible = true;
- }
- else
- {
- this.FormControlPrivacyStatusChild.DisplayState.UpgradeLinkIsVisible = false;
- }
-
// Connect refresh timer
this.TimerRefresh.Tick += TimerRefresh_Tick;
this.isStarted = true;
@@ -695,9 +687,6 @@
this.SetRating(provisionalRating);
}
- // Set IsDraft property
- this.omiProperties.IsDraft = omi.GetIsDraft();
-
/* Check if item is attached mail. For performance reasons,
* only do the whole check if an item has been loaded to the
* cache of attached mails and if item might be secure.
@@ -836,18 +825,14 @@
* current code runs before CryptableMailItem.MailItem_Reply
* or CryptableMailItem.MailItem_Forward.
*/
- if (omi.GetIsIncoming() || omi.GetIsInSentFolder())
+ if (omi.GetIsDraft())
{
- enableFormRegion = omi.GetIsDecryptAlwaysEnabled();
+ enableFormRegion = true;
+ this.cryptableMailItem.OriginallyEncryptedStatusUpdated += CryptableMailItem_OriginallyEncryptedStatusUpdated;
}
else
{
- enableFormRegion = omi.GetEnableProtection();
-
- if (enableFormRegion == false)
- {
- this.cryptableMailItem.OriginallyEncryptedStatusUpdated += CryptableMailItem_OriginallyEncryptedStatusUpdated;
- }
+ enableFormRegion = omi.GetIsDecryptAlwaysEnabled();
}
}
}
@@ -898,6 +883,7 @@
this.cryptableMailItem.GetMirrorCompleted -= MailItem_GetMirrorCompleted;
this.cryptableMailItem.Open -= MailItem_Open;
this.cryptableMailItem.Send -= MailItem_Send;
+ this.cryptableMailItem.OriginallyEncryptedStatusUpdated -= CryptableMailItem_OriginallyEncryptedStatusUpdated;
}
catch { }
@@ -910,22 +896,6 @@
}
/// <summary>
- /// Event handler for when the form region is expanded or collapsed.
- /// </summary>
- private void FormRegionPrivacyStatus_Expanded(object sender, EventArgs e)
- {
- /* This Outlook form region has a bug where clicking the '+' button to expand will also
- * raise a click event on the privacy status button. Basically, Outlook would fire the click event
- * (FormControlPrivacyStatusChild_PrivacyViewClick) immediately after the region is expanded even though at
- * the time it was clicked it was collapsed and the click already captured by the expander '+' button.
- * This code here works around that issue by disabling the manager form when the form region is collapsed.
- * Since the click event occurs BEFORE the expanded event, this will disable opening the manage privacy status
- * form in this situation.
- */
- this.isManagerFormEnabled = this.OutlookFormRegion.IsExpanded;
- }
-
- /// <summary>
/// Event handler called after the refresh timer has elapsed.
/// </summary>
private void TimerRefresh_Tick(object sender, EventArgs e)
@@ -1053,7 +1023,6 @@
{
try
{
- this.FormControlPrivacyStatusChild.DisplayState.Rating = e.ProcessedRating;
this.SetRating(e.ProcessedRating);
Log.Verbose("MailItem_ProcessingComplete: Status bar updated with rating " + Enum.GetName(typeof(pEpRating), e.ProcessedRating));
}
@@ -1096,10 +1065,6 @@
{
Log.Verbose("MailItem_ProcessingComplete: Error while checking if mail item is in outbox or updating inspector. " + ex.Message);
}
- finally
- {
- omi = null;
- }
/* Create the unencrypted preview if the mail item is encrypted and
* it is in an encrypted (untrusted) store
@@ -1125,6 +1090,58 @@
// While rare, just log the issue and stop the process
Log.Warning("MailItem_ProcessingComplete: Failed to start mirror location, " + ex.ToString());
}
+
+ /* OUT-470: Workaround until this is implemented in the engine:
+ * Only enable Force Protection if all recipients are grey
+ */
+ if (omi?.GetIsDraft() == true)
+ {
+ bool disableForceProtection = false;
+ Outlook.Recipients recipients = null;
+ Outlook.Recipient recipient = null;
+ PEPIdentity pEpIdentity = null;
+
+ try
+ {
+ recipients = omi?.Recipients;
+ if (omi.Recipients?.Count > 0)
+ {
+ for (int i = 1; i <= recipients.Count; i++)
+ {
+ recipient = recipients[i];
+ if ((PEPIdentity.Create(recipient, out pEpIdentity, false) == Globals.ReturnStatus.Success) &&
+ ((PEPIdentity.GetIsOwnIdentity(pEpIdentity.Address) ||
+ (ThisAddIn.PEPEngine.IdentityRating(pEpIdentity.ToCOMType()) >= pEpRating.pEpRatingReliable))))
+ {
+ disableForceProtection = true;
+ Log.Verbose("ToggleButtonForceProtection_GetEnabled: Secure recipient found. Disabling force protection.");
+ break;
+ }
+ }
+ }
+ else
+ {
+ // If there aren't any recipients (anymore), reset values
+ this.DisableForceProtection = false;
+ this.ForceProtection = false;
+ this.NeverUnsecure = false;
+ this.ForceUnencrypted = false;
+ }
+ }
+ catch (Exception ex)
+ {
+ Log.Error("ToggleButtonForceProtection_GetEnabled: Error occured. " + ex.ToString());
+ }
+ finally
+ {
+ recipient = null;
+ recipients = null;
+ }
+
+ this.DisableForceProtection = disableForceProtection;
+ }
+
+ omi = null;
}
}
}));
@@ -1218,14 +1235,10 @@
private void CryptableMailItem_OriginallyEncryptedStatusUpdated(object sender, EventArgs e)
{
// Process the mail item now that the cache is updated
- if (this.isEnabled == false &&
- this.cryptableMailItem.IsOriginallyEncrypted)
+ if (this.cryptableMailItem.IsOriginallyEncrypted)
{
- this.isEnabled = true;
this.TimerRefresh_Tick(null, new EventArgs());
}
-
- return;
}
/// <summary>
@@ -1290,7 +1303,7 @@
if ((Globals.ThisAddIn.Settings.IsSecurityLossWarningEnabled) &&
(this.cryptableMailItem.IsOriginallyEncrypted) &&
- (this.FormControlPrivacyStatusChild.DisplayState.Rating < pEpRating.pEpRatingUnreliable))
+ (this.Rating < pEpRating.pEpRatingUnreliable))
{
#if READER_RELEASE_MODE
@@ -1303,11 +1316,11 @@
cancel = true;
}
#else
- result = System.Windows.Forms.MessageBox.Show(this.ParentForm,
- pEp.Properties.Resources.Message_WarningSecurityLoss,
- pEp.Properties.Resources.Message_TitleConfirmOperation,
- MessageBoxButtons.YesNo,
- MessageBoxIcon.Warning);
+ result = MessageBox.Show(this.ParentForm,
+ Properties.Resources.Message_WarningSecurityLoss,
+ Properties.Resources.Message_TitleConfirmOperation,
+ MessageBoxButtons.YesNo,
+ MessageBoxIcon.Warning);
if (result == DialogResult.No)
{
@@ -1317,6 +1330,25 @@
#endif
}
+ if (cancel == false)
+ {
+ if ((this.ForceProtection) &&
+ (this.DisableForceProtection == false))
+ {
+ (this.OutlookItem as Outlook.MailItem)?.SetPEPProperty(MailItemExtensions.PEPProperty.ForceProtection, Guid.NewGuid().ToString());
+ }
+ else if (this.ForceUnencrypted)
+ {
+ (this.OutlookItem as Outlook.MailItem)?.SetPEPProperty(MailItemExtensions.PEPProperty.ForceUnencrypted, true);
+ }
+
+ if (this.NeverUnsecure)
+ {
+ (this.OutlookItem as Outlook.MailItem)?.SetPEPProperty(MailItemExtensions.PEPProperty.NeverUnsecure, true);
+ }
+
+ }
+
// Stop and disconnect the refresh timer
// This is necessary so an ongoing refresh doesn't try to access a mail item as it's being moved
if (cancel == false)
@@ -1430,46 +1462,5 @@
this.handshakeDialog = null;
}
}
-
- /// <summary>
- /// Event handler for when the manager form is closed.
- /// </summary>
- private void ManagerForm_FormClosed(object sender, FormClosedEventArgs e)
- {
- // Remove the reference held in the FormRegionPrivacyStatus so it stops getting updated
- if (this.managerForm != null)
- {
- this.managerForm.FormClosed -= ManagerForm_FormClosed;
- this.managerForm = null;
- }
-
- return;
- }
-
- /// <summary>
- /// Event handler for when the pEp website hyperlink is clicked.
- /// </summary>
- private void LinkLabelUpgrade_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
- {
- try
- {
- Process.Start(Globals.PEP_WEBSITE_UPGRADE_LINK);
- }
- catch (Exception ex)
- {
- Log.Error("LinkLabelUpgrade_LinkClicked: Unable to open website link, " + ex.ToString());
- }
-
- return;
- }
-
- /// <summary>
- /// Class used to store some properties of this form region's Outlook mail item.
- /// </summary>
- private class MailItemProperties
- {
- internal pEpRating Rating { get; set; } = pEpRating.pEpRatingUndefined;
- internal bool IsDraft { get; set; } = false;
- }
}
}
--- a/UI/HandshakeDialog.xaml.cs Mon Jul 16 17:01:23 2018 +0200
+++ b/UI/HandshakeDialog.xaml.cs Fri Jul 20 13:21:53 2018 +0200
@@ -127,7 +127,7 @@
this._Message = message;
this._IsIncoming = message.Direction == pEpMsgDirection.pEpDirIncoming;
this._IsDraft = isDraft;
- this._MessageRating = (this._IsDraft) ? message.GetOutgoingRating() : message.Rating;
+ this._MessageRating = (this._IsDraft) ? message.GetOutgoingRating() : AdapterExtensions.ReevaluateMessageRating(message);
try
{
--- a/UI/RibbonCustomizations.cs Mon Jul 16 17:01:23 2018 +0200
+++ b/UI/RibbonCustomizations.cs Fri Jul 20 13:21:53 2018 +0200
@@ -39,6 +39,130 @@
/**************************************************************
*
+ * Property accessors
+ *
+ *************************************************************/
+
+ /// <summary>
+ /// Gets whether the Force Protection option is disabled for the current mail item.
+ /// </summary>
+ /// <param name="control">The current button control.</param>
+ /// <returns>True if the Force Protection option is disabled for the current mail item, otherwise false.</returns>
+ internal bool GetDisableForceProtection(Office.IRibbonControl control)
+ {
+ return this.GetFormRegionPrivacyStatus(control)?.DisableForceProtection ?? false;
+ }
+
+ /// <summary>
+ /// Sets whether the Force Protection option should be disabled for the current mail item.
+ /// </summary>
+ /// <param name="control">The current button control.</param>
+ /// <param name="disable">Whether to disable the Force Protection option or not</param>
+ internal void SetDisableForceProtection(Office.IRibbonControl control, bool disable)
+ {
+ try
+ {
+ this.GetFormRegionPrivacyStatus(control).DisableForceProtection = disable;
+ }
+ catch (Exception ex)
+ {
+ Log.Error("SetDisableForceProtection: Error setting value. " + ex.ToString());
+ }
+ }
+
+ /// <summary>
+ /// Gets whether the current mail item is forcefully protected.
+ /// </summary>
+ /// <param name="control">The current button control.</param>
+ /// <returns>True if the current mail item is forcefully protected, otherwise false.</returns>
+ internal bool GetForceProtection(Office.IRibbonControl control)
+ {
+ return this.GetFormRegionPrivacyStatus(control)?.ForceProtection ?? false;
+ }
+
+ /// <summary>
+ /// Sets whether the current mail item should be forcefully protected or not.
+ /// </summary>
+ /// <param name="control">The current button control.</param>
+ /// <param name="forceProtection">Whether to enable Force Protection or not.</param>
+ internal void SetForceProtection(Office.IRibbonControl control, bool forceProtection)
+ {
+ try
+ {
+ this.GetFormRegionPrivacyStatus(control).ForceProtection = forceProtection;
+ }
+ catch (Exception ex)
+ {
+ Log.Error("SetForceProtection: Error setting value. " + ex.ToString());
+ }
+ }
+
+ /// <summary>
+ /// Gets whether the current mail item is forcefully unencrypted.
+ /// </summary>
+ /// <param name="control">The current button control.</param>
+ /// <returns>True if the current mail item is forcefully unencrypted, otherwise false.</returns>
+ internal bool GetForceUnencrypted(Office.IRibbonControl control)
+ {
+ return this.GetFormRegionPrivacyStatus(control)?.ForceUnencrypted ?? false;
+ }
+
+ /// <summary>
+ /// Sets whether the current mail item should be forcefully unencrypted or not.
+ /// </summary>
+ /// <param name="control">The current button control.</param>
+ /// <param name="forceUnencrypted">Whether to enable Force Unencrypted or not.</param>
+ internal void SetForceUnencrypted(Office.IRibbonControl control, bool forceUnencrypted)
+ {
+ try
+ {
+ this.GetFormRegionPrivacyStatus(control).ForceUnencrypted = forceUnencrypted;
+ }
+ catch (Exception ex)
+ {
+ Log.Error("SetForceUnencrypted: Error setting value. " + ex.ToString());
+ }
+ }
+
+ /// <summary>
+ /// Gets whether the current mail item has the Never Unsecure option set
+ /// </summary>
+ /// <param name="control">The current button control.</param>
+ /// <returns>True if the current mail item has the Never Unsecure option set, otherwise false.</returns>
+ internal bool GetNeverUnsecure(Office.IRibbonControl control)
+ {
+ return this.GetFormRegionPrivacyStatus(control)?.NeverUnsecure ?? false;
+ }
+
+ /// <summary>
+ /// Sets whether the current mail item should be forcefully unencrypted or not.
+ /// </summary>
+ /// <param name="control">The current button control.</param>
+ /// <param name="neverUnsecure">Whether to enable Force Unencrypted or not.</param>
+ internal void SetNeverUnsecure(Office.IRibbonControl control, bool neverUnsecure)
+ {
+ try
+ {
+ this.GetFormRegionPrivacyStatus(control).NeverUnsecure = neverUnsecure;
+ }
+ catch (Exception ex)
+ {
+ Log.Error("SetNeverUnsecure: Error setting value. " + ex.ToString());
+ }
+ }
+
+ /// <summary>
+ /// Gets the current UI rating as determined in the associated form region.
+ /// </summary>
+ /// <param name="control">The current button control.</param>
+ /// <returns>The pEpRating of the current message or undefined if an error occured.</returns>
+ private pEpRating GetRating(Office.IRibbonControl control)
+ {
+ return this.GetFormRegionPrivacyStatus(control)?.Rating ?? pEpRating.pEpRatingUndefined;
+ }
+
+ /**************************************************************
+ *
* Methods
*
*************************************************************/
@@ -279,13 +403,30 @@
}
/// <summary>
- /// Gets the current UI rating as determined in the associated form region.
+ /// Determines whether the Decrypt Always option is enabled for the current mail item.
/// </summary>
- /// <param name="control">The control to get its associated rating for.</param>
- /// <returns>The pEpRating or undefined if an error occured.</returns>
- private pEpRating GetRating(Office.IRibbonControl control)
+ /// <returns>True if the Decrypt Always option is enabled for the current mail item, otherwise false.</returns>
+ private bool GetIsDecryptAlwaysEnabled(Office.IRibbonControl control)
{
- return this.GetFormRegionPrivacyStatus(control)?.Rating ?? pEpRating.pEpRatingUndefined;
+ Outlook.MailItem omi = null;
+ bool isEnabled = PEPSettings.ACCOUNT_SETTING_IS_DECRYPT_ALWAYS_ENABLED_DEFAULT;
+
+ try
+ {
+ omi = this.GetMailItem(control);
+ isEnabled = omi?.GetIsDecryptAlwaysEnabled() ?? PEPSettings.ACCOUNT_SETTING_IS_DECRYPT_ALWAYS_ENABLED_DEFAULT;
+ }
+ catch (Exception ex)
+ {
+ isEnabled = PEPSettings.ACCOUNT_SETTING_IS_DECRYPT_ALWAYS_ENABLED_DEFAULT;
+ Log.Error("GetIsDecryptAlwaysEnabled: Error occured. " + ex.ToString());
+ }
+ finally
+ {
+ omi = null;
+ }
+
+ return isEnabled;
}
/// <summary>
@@ -627,7 +768,7 @@
try
{
Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
- this.GetFormRegionPrivacyStatus(control).BuildAndShowManager();
+ this.GetFormRegionPrivacyStatus(control)?.BuildAndShowManager();
}
catch (Exception ex)
{
@@ -653,7 +794,7 @@
// Yellow rating
case pEpRating.pEpRatingReliable:
{
- if (this.GetMailItem(control)?.GetIsForceUnencrypted() == true)
+ if (this.GetForceUnencrypted(control))
{
return Properties.Resources.ImagePrivacyStatusYellowProtectionDisabled;
}
@@ -668,7 +809,7 @@
case pEpRating.pEpRatingTrustedAndAnonymized:
case pEpRating.pEpRatingFullyAnonymous:
{
- if (this.GetMailItem(control)?.GetIsForceUnencrypted() == true)
+ if (this.GetForceUnencrypted(control))
{
return Properties.Resources.ImagePrivacyStatusGreenProtectionDisabled;
}
@@ -679,11 +820,22 @@
}
// No color rating
+ case pEpRating.pEpRatingUnencrypted:
+ case pEpRating.pEpRatingUnencryptedForSome:
+ {
+ if ((this.GetForceProtection(control)) &&
+ (this.GetDisableForceProtection(control) == false))
+ {
+ return Properties.Resources.ImageRatingYellow;
+ }
+ else
+ {
+ return Properties.Resources.ImagePrivacyStatusNoColor;
+ }
+ }
case pEpRating.pEpRatingUndefined:
case pEpRating.pEpRatingCannotDecrypt:
case pEpRating.pEpRatingHaveNoKey:
- case pEpRating.pEpRatingUnencrypted:
- case pEpRating.pEpRatingUnencryptedForSome:
case pEpRating.pEpRatingUnreliable:
default:
return Properties.Resources.ImagePrivacyStatusNoColor;
@@ -715,7 +867,7 @@
return Properties.Resources.PrivacyStatus_RatingUnderAttackText;
case pEpRating.pEpRatingReliable:
{
- if (this.GetMailItem(control)?.GetIsForceUnencrypted() == true)
+ if (this.GetForceUnencrypted(control))
{
return Properties.Resources.PrivacyStatus_RatingUnencryptedText;
}
@@ -723,12 +875,12 @@
{
return Properties.Resources.PrivacyStatus_RatingReliableText;
}
- }
+ }
case pEpRating.pEpRatingTrusted:
case pEpRating.pEpRatingTrustedAndAnonymized:
case pEpRating.pEpRatingFullyAnonymous:
{
- if (this.GetMailItem(control)?.GetIsForceUnencrypted() == true)
+ if (this.GetForceUnencrypted(control))
{
return Properties.Resources.PrivacyStatus_RatingUnencryptedText;
}
@@ -736,12 +888,22 @@
{
return Properties.Resources.PrivacyStatus_RatingTrustedText;
}
- }
+ }
case pEpRating.pEpRatingCannotDecrypt:
case pEpRating.pEpRatingHaveNoKey:
return Properties.Resources.PrivacyStatus_RatingHaveNoKeyText;
case pEpRating.pEpRatingUnencrypted:
- return Properties.Resources.PrivacyStatus_RatingUnencryptedText;
+ {
+ if ((this.GetForceProtection(control)) &&
+ (this.GetDisableForceProtection(control) == false))
+ {
+ return Properties.Resources.PrivacyStatus_RatingReliableText;
+ }
+ else
+ {
+ return Properties.Resources.PrivacyStatus_RatingUnencryptedText;
+ }
+ }
case pEpRating.pEpRatingUnencryptedForSome:
return Properties.Resources.PrivacyStatus_RatingUnencryptedForSomeText;
case pEpRating.pEpRatingUnreliable:
@@ -757,7 +919,49 @@
/// </summary>
public bool ButtonPrivacyStatus_GetVisible(Office.IRibbonControl control)
{
- return this.GetIsPEPEnabled(control);
+ /* Visible if pEp enabled.
+ * If pEp is disabled, only visible in draft windows (so user can Enable Protection)
+ * or if DecryptAlways option is set.
+ */
+ bool visible = true;
+
+ if (this.GetIsPEPEnabled(control) == false)
+ {
+ visible = false;
+ dynamic window = null;
+ Outlook.MailItem omi = null;
+
+ try
+ {
+ // Get the parent window
+ window = control.Context as Outlook.Explorer;
+ if (window != null)
+ {
+ visible = this.GetIsDecryptAlwaysEnabled(control);
+ }
+ else
+ {
+ window = control.Context as Outlook.Inspector;
+ if (window != null)
+ {
+ omi = this.GetMailItem(control);
+ visible = ((omi?.GetIsDraft() == true) ||
+ (this.GetIsDecryptAlwaysEnabled(control)));
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ Log.Error("ButtonPrivacyStatus_GetVisible: Error occured. " + ex.ToString());
+ }
+ finally
+ {
+ omi = null;
+ window = null;
+ }
+ }
+
+ return visible;
}
/// <summary>
@@ -778,7 +982,15 @@
/// </summary>
public void ToggleButtonForceUnencrypted_Click(Office.IRibbonControl control, bool isPressed)
{
- this.SetProperty(control, MailItemExtensions.PEPProperty.ForceUnencrypted, isPressed);
+ this.SetForceUnencrypted(control, isPressed);
+
+ // Disable Force Protection and Never Unsecure if needed
+ if (isPressed)
+ {
+ this.SetForceProtection(control, false);
+ this.SetNeverUnsecure(control, false);
+ }
+
RibbonCustomizations.Invalidate();
}
@@ -787,13 +999,16 @@
/// </summary>
public bool ToggleButtonForceUnencrypted_GetEnabled(Office.IRibbonControl control)
{
- // When a message is marked as never unsecure or forcefully proteced, it cannot be forcefully unencrypted
- if (((bool)this.GetProperty(control, MailItemExtensions.PEPProperty.NeverUnsecure) || (this.GetProperty(control, MailItemExtensions.PEPProperty.ForceProtection) != null)) ||
- (((bool)this.GetProperty(control, MailItemExtensions.PEPProperty.ForceUnencrypted) == false) &&
- (this.GetRating(control) == pEpRating.pEpRatingUnencrypted)))
+ /* The button is disabled if
+ * - Rating is lower than reliable
+ * - Force Protection or Never Unsecure are enabled and not overridden
+ */
+ if (((this.GetRating(control) < pEpRating.pEpRatingReliable) ||
+ (this.GetNeverUnsecure(control))) ||
+ ((this.GetForceProtection(control)) && (this.GetDisableForceProtection(control) == false)))
{
return false;
- }
+ }
else
{
return true;
@@ -801,21 +1016,6 @@
}
/// <summary>
- /// Callback to get the image for the ToggleButtonForceUnencrypted.
- /// </summary>
- public System.Drawing.Bitmap ToggleButtonForceUnencrypted_GetImage(Office.IRibbonControl control)
- {
- if ((bool)this.GetProperty(control, MailItemExtensions.PEPProperty.ForceUnencrypted))
- {
- return Properties.Resources.ImageForceUnencOn;
- }
- else
- {
- return Properties.Resources.ImageForceUnencOff;
- }
- }
-
- /// <summary>
/// Callback to get the label text for the ToggleButtonForceUnencrypted.
/// </summary>
public string ToggleButtonForceUnencrypted_GetLabel(Office.IRibbonControl control)
@@ -828,7 +1028,7 @@
/// </summary>
public bool ToggleButtonForceUnencrypted_GetPressed(Office.IRibbonControl control)
{
- return ((bool)this.GetProperty(control, MailItemExtensions.PEPProperty.ForceUnencrypted));
+ return this.GetForceUnencrypted(control);
}
/// <summary>
@@ -859,13 +1059,12 @@
{
this.SetProperty(control, MailItemExtensions.PEPProperty.EnableProtection, isPressed);
- // If protection is disabled, disable also never unsecure
+ // If protection is disabled, disable also force protected and never unsecure
if (isPressed == false)
{
- this.SetProperty(control, MailItemExtensions.PEPProperty.NeverUnsecure, false);
+ this.SetForceProtection(control, false);
+ this.SetNeverUnsecure(control, false);
}
-
- RibbonCustomizations.Invalidate();
}
/// <summary>
@@ -878,21 +1077,6 @@
}
/// <summary>
- /// Callback to get the image for the ToggleButtonEnableProtection.
- /// </summary>
- public System.Drawing.Bitmap ToggleButtonEnableProtection_GetImage(Office.IRibbonControl control)
- {
- if (this.GetProperty(control, MailItemExtensions.PEPProperty.EnableProtection) as bool? ?? false)
- {
- return Properties.Resources.ImageForceUnencOff;
- }
- else
- {
- return Properties.Resources.ImageForceUnencOn;
- }
- }
-
- /// <summary>
/// Callback to get the label text for the ToggleButtonEnableProtection.
/// </summary>
public string ToggleButtonEnableProtection_GetLabel(Office.IRibbonControl control)
@@ -905,7 +1089,7 @@
/// </summary>
public bool ToggleButtonEnableProtection_GetPressed(Office.IRibbonControl control)
{
- return ((bool)this.GetProperty(control, MailItemExtensions.PEPProperty.EnableProtection));
+ return ((this.GetProperty(control, MailItemExtensions.PEPProperty.EnableProtection) as bool?) ?? false);
}
/// <summary>
@@ -934,25 +1118,15 @@
/// </summary>
public void ToggleButtonForceProtection_Click(Office.IRibbonControl control, bool isPressed)
{
- // If button is pressed, set new Guid, else delete it
- this.SetProperty(control, MailItemExtensions.PEPProperty.ForceProtection, (isPressed ? Guid.NewGuid().ToString() : null));
- RibbonCustomizations.Invalidate();
- }
+ this.SetForceProtection(control, isPressed);
- /// <summary>
- /// Callback to get the image for the ToggleButtonForceProtection.
- /// </summary>
- public System.Drawing.Bitmap ToggleButtonForceProtection_GetImage(Office.IRibbonControl control)
- {
- // Placeholder until design is ready
- if (this.GetProperty(control, MailItemExtensions.PEPProperty.ForceProtection) != null)
+ // If protection is disabled, disable also never unsecure
+ if (isPressed == false)
{
- return Properties.Resources.ImageForceUnencOff;
+ this.SetNeverUnsecure(control, isPressed);
}
- else
- {
- return Properties.Resources.ImageForceUnencOn;
- }
+
+ RibbonCustomizations.Invalidate();
}
/// <summary>
@@ -960,25 +1134,28 @@
/// </summary>
public bool ToggleButtonForceProtection_GetEnabled(Office.IRibbonControl control)
{
- // If button is visible, it is also enabled
bool enabled = false;
- if (this.GetIsSMIMEEnabled(control))
+ /* The button is enabled when:
+ * 1. No S/MIME option is enabled
+ * 2. Force Unencrypted is not enabled
+ * 3. Rating is Unsecure
+ */
+ if ((this.GetIsSMIMEEnabled(control)) ||
+ (this.GetDisableForceProtection(control)))
{
return false;
}
if (this.GetIsPEPEnabled(control))
{
- enabled = (this.GetProperty(control, MailItemExtensions.PEPProperty.ForceUnencrypted) as bool? == false) &&
- ((this.GetRating(control) == pEpRating.pEpRatingUnencrypted) || (this.GetRating(control) == pEpRating.pEpRatingUnencryptedForSome)) ||
- (this.GetProperty(control, MailItemExtensions.PEPProperty.ForceProtection) != null);
+ enabled = ((this.GetRating(control) == pEpRating.pEpRatingUnencrypted) &&
+ (this.GetForceUnencrypted(control) == false));
}
else
{
- enabled = (this.GetProperty(control, MailItemExtensions.PEPProperty.EnableProtection) as bool? == true) &&
- ((this.GetRating(control) == pEpRating.pEpRatingUnencrypted) || (this.GetRating(control) == pEpRating.pEpRatingUnencryptedForSome)) ||
- (this.GetProperty(control, MailItemExtensions.PEPProperty.ForceProtection) != null);
+ enabled = ((this.GetRating(control) == pEpRating.pEpRatingUnencrypted) &&
+ ((this.GetProperty(control, MailItemExtensions.PEPProperty.EnableProtection) as bool?) ?? false));
}
return enabled;
@@ -997,7 +1174,8 @@
/// </summary>
public bool ToggleButtonForceProtection_GetPressed(Office.IRibbonControl control)
{
- return (this.GetProperty(control, MailItemExtensions.PEPProperty.ForceProtection) != null);
+ return ((this.GetForceProtection(control)) &&
+ (this.GetDisableForceProtection(control) == false));
}
/// <summary>
@@ -1026,7 +1204,7 @@
/// </summary>
public void ToggleButtonNeverUnsecure_Click(Office.IRibbonControl control, bool isPressed)
{
- this.SetProperty(control, MailItemExtensions.PEPProperty.NeverUnsecure, isPressed);
+ this.SetNeverUnsecure(control, isPressed);
RibbonCustomizations.Invalidate();
}
@@ -1035,25 +1213,10 @@
/// </summary>
public bool ToggleButtonNeverUnsecure_GetEnabled(Office.IRibbonControl control)
{
- // Enabled if not forcefully unencrypted, rating >= Reliable, no S/MIME enabled and no BCC recipients
- return (((this.GetProperty(control, MailItemExtensions.PEPProperty.ForceUnencrypted) as bool?) != true) &&
- (this.GetRating(control) >= pEpRating.pEpRatingReliable) &&
- (this.GetIsSMIMEEnabled(control) == false));
- }
-
- /// <summary>
- /// Callback to get the image for the ToggleButtonNeverUnsecure.
- /// </summary>
- public System.Drawing.Bitmap ToggleButtonNeverUnsecure_GetImage(Office.IRibbonControl control)
- {
- if ((bool)this.GetProperty(control, MailItemExtensions.PEPProperty.NeverUnsecure))
- {
- return Properties.Resources.ImageNeverUnsecureOn;
- }
- else
- {
- return Properties.Resources.ImageNeverUnsecureOff;
- }
+ // Enabled if not forcefully unencrypted, rating >= Reliable (or force protection), no S/MIME enabled and no BCC recipients
+ return (((this.GetRating(control) >= pEpRating.pEpRatingReliable) || (this.GetForceProtection(control)) && (this.ToggleButtonForceProtection_GetEnabled(control))) &&
+ (this.GetForceUnencrypted(control) == false) &&
+ (this.GetIsSMIMEEnabled(control) == false));
}
/// <summary>
@@ -1069,7 +1232,7 @@
/// </summary>
public bool ToggleButtonNeverUnsecure_GetPressed(Office.IRibbonControl control)
{
- return ((bool)this.GetProperty(control, MailItemExtensions.PEPProperty.NeverUnsecure));
+ return this.GetNeverUnsecure(control);
}
/// <summary>