Ejemplo n.º 1
0
        public string FindSendAsAddress(ZPushAccount zpush, GABUser user)
        {
            GABHandler handler = FeatureGAB.FindGABForAccount(zpush);

            if (handler != null && handler.Contacts != null)
            {
                // Look for the email address. If found, use the account associated with the GAB
                using (ISearch <IContactItem> search = handler.Contacts.Search <IContactItem>())
                {
                    search.AddField("urn:schemas:contacts:customerid").SetOperation(SearchOperation.Equal, user.UserName);
                    using (IContactItem result = search.SearchOne())
                    {
                        Logger.Instance.Trace(this, "GAB Search for send-as {0}: {1}", zpush, result);
                        if (result != null)
                        {
                            // Try resolving by email
                            Logger.Instance.Trace(this, "Resolving send-as by email address {0}: {1}", user.UserName, result.Email1Address);
                            return(result.Email1Address);
                        }
                    }
                }
            }
            else
            {
                Logger.Instance.Warning(this, "GAB handler not found for account: {0}", zpush);
            }

            Logger.Instance.Warning(this, "Unable to resolve send-as: {0}", user.UserName);
            return(null);
        }
        private void ReplacePlaceholders(GABHandler gab, params string[] signatures)
        {
            ContactStringReplacer replacer = null;

            try
            {
                replacer = ContactStringReplacer.FindUs(gab);
                if (replacer != null)
                {
                    foreach (string signatureName in signatures)
                    {
                        ReplacePlaceholders(replacer, signatureName);
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Instance.Error(this, "Exception in ReplacePlaceholders: {0}", e);
            }
            finally
            {
                if (replacer != null)
                {
                    replacer.Dispose();
                }
            }
        }
Ejemplo n.º 3
0
        public StoreTreeNode(SharedFoldersManager folders, GABHandler gab, GABUser user, string text,
                             Dictionary <BackendId, SharedFolder> currentFolders)
            :
            base(text)
        {
            this._initialShares = currentFolders;
            this._feature       = folders.Feature;
            this._gab           = gab;
            this._user          = user;

            // Create an empty current state. When loading the nodes, the shares will be added. This has the benefit of
            // cleaning up automatically any obsolote shares.
            this._currentShares = new Dictionary <BackendId, SharedFolder>();

            ChildLoader = new UserFolderLoader(this, folders, user);
            ChildLoader.ReloadOnCloseOpen = true;
            HasCheckBox = false;

            // TODO: better icons, better way of handling this
            ImageIndex = user == GABUser.USER_PUBLIC ? 0 : 11;

            // Reloader
            _reloader           = new KAnimator();
            _reloader.Animation = Properties.Resources.TreeLoading;
            _reloader.Visible   = false;
            _reloader.Click    += (s, e) =>
            {
                ChildLoader.Reload();
            };
            Control = _reloader;
        }
Ejemplo n.º 4
0
        public StoreTreeNode(SharedFoldersManager folders, GABHandler gab, GABUser user, string sendAsAddress, string text,
                             Dictionary <BackendId, SharedFolder> currentFolders, bool isShared, bool showRemindersWholeStore)
            :
            base(text)
        {
            this._initialShares = currentFolders;
            // Patch in send as address
            foreach (SharedFolder share in _initialShares.Values)
            {
                if (string.IsNullOrWhiteSpace(share.SendAsAddress))
                {
                    share.SendAsAddress = sendAsAddress;
                }
            }
            this._feature       = folders.Feature;
            this._featureSendAs = ThisAddIn.Instance.GetFeature <FeatureSendAs>();
            this._account       = folders.Account;
            this._gab           = gab;
            this._user          = user;
            this._sendAsAddress = sendAsAddress;
            this.IsReadOnly     = false;
            this._isShared      = isShared;

            // Create an empty current state. When loading the nodes, the shares will be added. This has the benefit of
            // cleaning up automatically any obsolote shares.
            this._currentShares = new Dictionary <BackendId, SharedFolder>();

            ChildLoader = new UserFolderLoader(this, folders, user);
            ChildLoader.ReloadOnCloseOpen = true;
            // Can only open the whole store if it's supported and there's an email address, as that's needed to open it
            // However, if it's already opened, we can remove it without the email address
            HasCheckBox = folders.SupportsWholeStore && (!string.IsNullOrWhiteSpace(user.EmailAddress) || isShared);
            ApplyReadOnly(this, IsReadOnly);

            // TODO: better icons, better way of handling this
            ImageIndex = user == GABUser.USER_PUBLIC ? 0 : 11;

            // Reloader
            _reloader           = new KAnimator();
            _reloader.Animation = Properties.Resources.TreeLoading;
            _reloader.Visible   = false;
            _reloader.Click    += (s, e) =>
            {
                ChildLoader.Reload();
            };
            Control = _reloader;

            // Set up sharing
            WantShare            = isShared;
            ShowRemindersInitial = showRemindersWholeStore;
            ShowReminders        = ShowRemindersInitial;
        }
Ejemplo n.º 5
0
            public GABDataSource(GABHandler gab)
            {
                this._gab = gab;

                _users = new List <GABUser>();
                foreach (IItem item in _gab.Contacts.Items.Sort("FullName", false))
                {
                    if (item is IContactItem)
                    {
                        _users.Add(new GABUser((IContactItem)item));
                    }
                }
            }
        private string StoreSignature(ISignatures signatures, ZPushAccount account, Signature signatureInfo)
        {
            string name = GetSignatureName(signatures, account, signatureInfo.name);

            // Remove any existing signature
            try
            {
                ISignature signature = signatures.Get(name);
                if (signature != null)
                {
                    try
                    {
                        signature.Delete();
                    }
                    finally
                    {
                        signature.Dispose();
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Instance.Error(this, "Unable to delete signature {0}: {1}", name, e);
            }

            // Create the new signature
            using (ISignature signature = signatures.Add(name))
            {
                if (!HasPlaceholders(signatureInfo))
                {
                    // Simple, set signature straight away
                    signature.SetContent(signatureInfo.content, signatureInfo.isHTML ? ISignatureFormat.HTML : ISignatureFormat.Text);
                }
                else
                {
                    // There are placeholders. Create a template and hook into the GAB for patching
                    signature.SetContentTemplate(signatureInfo.content, signatureInfo.isHTML ? ISignatureFormat.HTML : ISignatureFormat.Text);

                    // Try replacing straight away
                    GABHandler gab = FeatureGAB.FindGABForAccount(account);
                    if (gab != null)
                    {
                        ReplacePlaceholders(gab, name);
                    }
                }
            }

            return(name);
        }
Ejemplo n.º 7
0
        internal IRecipient FindSendAsSender(ZPushAccount zpush, GABUser user)
        {
            // First try a simple resolve, this will work if the username is unique
            IRecipient recip = ThisAddIn.Instance.ResolveRecipient(user.UserName);

            if (recip != null)
            {
                // If it's resolved, we're good. Otherwise dispose and continue
                if (recip.IsResolved)
                {
                    return(recip);
                }
                else
                {
                    recip.Dispose();
                }
            }

            // Search through GAB to find the user
            if (GABLookup)
            {
                GABHandler handler = FeatureGAB.FindGABForAccount(zpush);
                if (handler != null && handler.Contacts != null)
                {
                    // Look for the email address. If found, use the account associated with the GAB
                    using (ISearch <IContactItem> search = handler.Contacts.Search <IContactItem>())
                    {
                        search.AddField("urn:schemas:contacts:customerid").SetOperation(SearchOperation.Equal, user.UserName);
                        using (IContactItem result = search.SearchOne())
                        {
                            if (result != null)
                            {
                                // Try resolving by email
                                return(ThisAddIn.Instance.ResolveRecipient(result.Email1Address));
                            }
                        }
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 8
0
        private void CheckUpgradesGabSynced(GABHandler gab)
        {
            ThisAddIn.Instance.InUI(() =>
            {
                ZPushAccount account = gab.ActiveAccount;
                ICollection <SharedFolder> shares = _sharedFolders.GetCachedFolders(account);
                if (shares == null)
                {
                    using (SharedFoldersManager manager = _sharedFolders.Manage(account))
                    {
                        shares = manager.GetCurrentShares(null);
                    }
                }

                if (shares != null)
                {
                    UpdateSendAsAddresses(account, shares, true);
                }
            }, false);
        }
        public static ContactStringReplacer FromGAB(GABHandler gab, GABUser user)
        {
            if (gab?.Contacts == null || user == null)
            {
                return(null);
            }

            using (ISearch <IContactItem> search = gab.Contacts.Search <IContactItem>())
            {
                search.AddField("urn:schemas:contacts:customerid").SetOperation(SearchOperation.Equal, user.UserName);
                IItem        result  = search.SearchOne();
                IContactItem contact = result as IContactItem;
                if (result != null && result != contact)
                {
                    result.Dispose();
                }

                return(new ContactStringReplacer(contact));
            }
        }
        public static ContactStringReplacer FindUs(GABHandler gab)
        {
            // Look for the email address. If found, use the account associated with the GAB
            using (ISearch <IContactItem> search = gab.Contacts.Search <IContactItem>())
            {
                IAccount account = gab.ActiveAccount.Account;

                search.AddField("urn:schemas:contacts:customerid").SetOperation(SearchOperation.Equal, account.UserName);
                IItem        result = search.SearchOne();
                IContactItem us     = result as IContactItem;
                if (result != null && result != us)
                {
                    result.Dispose();
                    return(null);
                }

                if (us == null)
                {
                    return(null);
                }

                return(new ContactStringReplacer(us));
            }
        }
 private void GAB_SyncFinished(GABHandler gab)
 {
     ReplacePlaceholders(gab, gab.ActiveAccount.Account.SignatureNewMessage, gab.ActiveAccount.Account.SignatureNewMessage);
 }
 public GABDataSource(GABHandler gab)
 {
     this._gab = gab;
     Limit     = 10;
 }
 public GABLookupControl(GABHandler gab)
 {
     InitializeComponent();
     GAB = gab;
 }