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); }
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 IItem FindItemById(string id) { using (ISearch <IItem> search = Contacts.Search <IItem>()) { search.AddField(PROP_GAB_ID, true).SetOperation(SearchOperation.Equal, id); return(search.SearchOne()); } }
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); }
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 ProcessMessage(CompletionTracker completion, IZPushItem item) { if (!_feature.ProcessMessage) { return; } // Check if the message is for the current sequence ChunkIndex?optionalIndex = ChunkIndex.Parse(item.Subject); if (optionalIndex == null) { Logger.Instance.Trace(this, "Not a chunk: {0}", item.Subject); return; } if (optionalIndex.Value.numberOfChunks != CurrentSequence) { // Try to update the current sequence; this message may indicate that it has changed DetermineSequence(); // If it is still not for the current sequence, it's an old message if (optionalIndex.Value.numberOfChunks != CurrentSequence) { Logger.Instance.Trace(this, "Skipping, wrong sequence: {0}", item.Subject); return; } } ChunkIndex index = optionalIndex.Value; // Check if the message is up to date string lastProcessed = GetChunkStateString(index); if (lastProcessed == item.Location) { Logger.Instance.Trace(this, "Already up to date: {0} - {1}", item.Subject, item.Location); return; } // Process it Logger.Instance.Trace(this, "Processing: {0} - {1} - {2}", item.Subject, item.Location, lastProcessed); _feature?.BeginProcessing(); try { if (_feature.ProcessMessageDeleteExisting) { // Delete the old contacts from this chunk using (ISearch <IItem> search = Contacts.Search <IItem>()) { search.AddField(PROP_SEQUENCE, true).SetOperation(SearchOperation.Equal, index.numberOfChunks); search.AddField(PROP_CHUNK, true).SetOperation(SearchOperation.Equal, index.chunk); foreach (IItem oldItem in search.Search()) { Logger.Instance.Trace(this, "Deleting GAB entry: {0}", oldItem.Subject); oldItem.Delete(); } } } // Create the new contacts ProcessChunkBody(completion, item, index); // Update the state SetChunkStateString(index, item.Location); } finally { _feature?.EndProcessing(); } }