diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/SharedFolders/SharedFoldersDialog.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/SharedFolders/SharedFoldersDialog.cs index ff3bd75..bcd3396 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/SharedFolders/SharedFoldersDialog.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/SharedFolders/SharedFoldersDialog.cs @@ -278,22 +278,7 @@ namespace Acacia.Features.SharedFolders if (folderNode != null) { // See if we can obtain it from a parent - for (KTreeNode current = folderNode.Parent; current is FolderTreeNode; current = current.Parent) - { - FolderTreeNode parentNode = (FolderTreeNode)current; - if (parentNode.SharedFolder == null) - break; - - if (parentNode.SharedFolder.FlagSendAsOwner) - { - if (!string.IsNullOrWhiteSpace(parentNode.SharedFolder.SendAsAddress)) - { - folder.SendAsAddress = parentNode.SharedFolder.SendAsAddress; - break; - } - } - else break; - } + TryInitSendAsAddressParent(folderNode as FolderTreeNode); if (!string.IsNullOrWhiteSpace(folder.SendAsAddress)) continue; @@ -787,8 +772,7 @@ namespace Acacia.Features.SharedFolders checkSendAs.ThreeState = true; } - textSendAsAddress.Text = ""; - TryInitSendAsAddress(); + textSendAsAddress.Text = TryInitSendAsAddress(); EnableSendAsAddress(); } // Reminders shown if any node supports it @@ -896,13 +880,20 @@ namespace Acacia.Features.SharedFolders } } - private void TryInitSendAsAddress() + private string TryInitSendAsAddress() { // Initialise to the send-as address specified for an existing share, or a simple GAB lookup otherwise string email = _optionSendAsNodes[0].SharedFolder?.SendAsAddress ?? _featureSendAs?.FindSendAsAddress(_account, _optionSendAsNodes[0].AvailableFolder.Store); + if (string.IsNullOrEmpty(email)) + { + // Try to initialise from the parent + TryInitSendAsAddressParent(_optionSendAsNodes[0]); + email = _optionSendAsNodes[0].SharedFolder?.SendAsAddress; + } + if (!string.IsNullOrEmpty(email)) { // Set the entry field @@ -923,6 +914,30 @@ namespace Acacia.Features.SharedFolders MessageBoxButtons.OK, MessageBoxIcon.Information); } } + return email; + } + + private void TryInitSendAsAddressParent(FolderTreeNode node) + { + if (node == null) + return; + + for (KTreeNode current = node.Parent; current is FolderTreeNode; current = current.Parent) + { + FolderTreeNode parentNode = (FolderTreeNode)current; + if (parentNode.SharedFolder == null) + break; + + if (parentNode.SharedFolder.FlagSendAsOwner) + { + if (!string.IsNullOrWhiteSpace(parentNode.SharedFolder.SendAsAddress)) + { + node.SharedFolder.SendAsAddress = parentNode.SharedFolder.SendAsAddress; + break; + } + } + else break; + } } private void EnableSendAsAddress() @@ -948,25 +963,6 @@ namespace Acacia.Features.SharedFolders if (node.SharedFolder.SendAsAddress != textSendAsAddress.Text) { node.SharedFolder = node.SharedFolder.WithSendAsAddress(textSendAsAddress.Text); - - // Try any children - ApplySendAsAddressChildren(node, textSendAsAddress.Text); - } - } - } - - private void ApplySendAsAddressChildren(FolderTreeNode node, string address) - { - foreach(FolderTreeNode child in node.Children) - { - if (child.SharedFolder == null || !child.SharedFolder.FlagSendAsOwner) - continue; - - if (string.IsNullOrWhiteSpace(child.SharedFolder.SendAsAddress)) - { - child.SharedFolder = child.SharedFolder.WithSendAsAddress(address); - - ApplySendAsAddressChildren(child, address); } } } diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ZPush/API/SharedFolders/SharedFolder.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ZPush/API/SharedFolders/SharedFolder.cs index 7eaff52..51f6dd6 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ZPush/API/SharedFolders/SharedFolder.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ZPush/API/SharedFolders/SharedFolder.cs @@ -169,7 +169,7 @@ namespace Acacia.ZPush.API.SharedFolders private SharedFolder DoClone(SoapData newData) { SharedFolder clone = new SharedFolder(newData); - clone.SendAsAddress = SendAsAddress; + clone._sendAsAddress = SendAsAddress; return clone; } @@ -210,10 +210,15 @@ namespace Acacia.ZPush.API.SharedFolders #region Send as + private string _sendAsAddress; + public string SendAsAddress { - get; - set; + get { return _sendAsAddress; } + set + { + this._sendAsAddress = value; + } } public SharedFolder WithSendAsAddress(string sendAs)