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);
        }
        internal ZPushAccount FindZPushAccount(string username)
        {
            // Search through GABs
            if (DoGABLookup)
            {
                FeatureGAB gab = ThisAddIn.Instance.GetFeature <FeatureGAB>();
                if (gab != null)
                {
                    foreach (GABHandler handler in gab.GABHandlers)
                    {
                        ZPushAccount account = handler.ActiveAccount;
                        if (account != 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:email1").SetOperation(SearchOperation.Equal, username);
                                using (IItem result = search.SearchOne())
                                {
                                    if (result != null)
                                    {
                                        return(account);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // Fall back to default account
            return(DefaultAccount);
        }
Esempio n. 3
0
        public SharedFoldersDialog(FeatureSharedFolders feature, ZPushAccount account, SyncId initial = null)
        {
            this._account       = account;
            this._folders       = feature.Manage(account);
            this._initialSyncId = initial;

            InitializeComponent();

            // TODO: make a specialised class out of this
            this.kTreeFolders.Images = new OutlookImageList(
                "NewFolder",              // Other
                "JunkEmailMarkAsNotJunk", // Inbox
                "GoDrafts",               // Drafts
                "RecycleBin",             // WasteBasket
                "ReceiveMenu",            // SentMail
                "NewFolder",              // Outbox
                "ShowTaskPage",           // Task
                "ShowAppointmentPage",    // Appointment
                "ShowContactPage",        // Contact
                "NewNote",                // Note
                "ShowJournalPage",        // Journal
                "LastModifiedBy"          // Store

                ).Images;

            // Add the email address to the title
            Text = string.Format(Text, account.Account.SmtpAddress);

            // Set up options
            ShowOptions(new KTreeNode[0]);

            // Set up user selector
            gabLookup.GAB = FeatureGAB.FindGABForAccount(account);
        }
 public override void Startup()
 {
     Watcher.AccountDiscovered += Watcher_AccountDiscovered;
     _gab = ThisAddIn.Instance.GetFeature <FeatureGAB>();
     if (_gab != null)
     {
         _gab.SyncFinished += GAB_SyncFinished;
     }
     Watcher.Sync.AddTask(this, Name, Periodic_Sync);
 }
        private void CheckUpgrades()
        {
            // To determine the send-as address, we need the GAB. So wait for that to finish updating.
            FeatureGAB gab = ThisAddIn.Instance.GetFeature <FeatureGAB>();

            if (gab != null)
            {
                gab.SyncFinished += CheckUpgradesGabSynced;
            }
        }
        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);
        }
Esempio 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);
        }