none
Find or Restrict all cc and bcc RRS feed

  • Question

  • how can i find or restrict all cc and bss for a specific user?

    when i'm trying the restrict with 'from' i get all the MailItems:

    MAPIFolderInboxFolder = null;

    InboxFolder = mapiNamespace.GetDefaultFolder(

                         OlDefaultFolders.olFolderInbox);

    ItemsItems = InboxFolder.Items.Restrict("[from] = alex");

    but if i'm trying to change [from] to [to] or [cc] it wont work.

    help plz?

    even finding all mails that were sent to me or cc to me will help.

    thanks.


    • Edited by redgolda Tuesday, August 7, 2012 7:35 AM
    Tuesday, August 7, 2012 6:44 AM

Answers

  • Ken,

    Aha, double quotes around the schema namespace, single quotes and percent signs around the search string.  And, VB single quotes don't need escaping within string literals.  Bleah to poorly documented functions, I say.

    Which 'Customize View' dialog are you referring to in particular? 

    redgolda,

    Use the following:

    .Restrict("@SQL=""http://schemas.microsoft.com/mapi/proptag/0x########"" LIKE '%searchString%'")

    Substitute the desired search-text for searchString ('%alex%'), and the following codes for the ######## depending on which field you want to search:

    • To: 0E04001E
    • Cc: 0E03001E
    • Bcc: 0E02001E
    • Subject: 0037001E
    • Sender's email address: 0C1F001E
    • Sender's name: 0C1A001E

    All eight characters in the codes must be entered, including the leading zeros.  I don't believe it's possible to search email bodies in this fashion.

    The search is insensitive to the case of searchString, as far as I can tell.

    -Brian

    • Marked as answer by redgolda Tuesday, August 14, 2012 6:55 AM
    Tuesday, August 7, 2012 6:11 PM
  • You should, but make sure to use the entire property tag:
     

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "redgolda" <=?utf-8?B?cmVkZ29sZGE=?=> wrote in message news:2cb9144b-e40e-42a4-b738-ffc4948ed0f7...

    thats ok :) i'll try everything tomorrow.

    what if i'm searching for by mail address when the contact is already saved in my address book (so i see his name and not the e-mail address)?
    will i find his mails by searching by mail with the field [Sender's email address: 0C1F001E]?


    Ken Slovak MVP - Outlook
    Tuesday, August 7, 2012 7:30 PM
    Moderator

All replies

  • Set Results = f.Items.Find("[to] = 'some recipient name'")

    works just fine. Try to put name in ''

    Tuesday, August 7, 2012 7:59 AM
  • I just spent some time fiddling around with the .Restrict function, and it looks like it's sensitive to the form of the email address used to send messages.  In particular, .Restrict will only find the string you put in if it *exactly matches* what's listed in the email header.

    For example, I have one message that I'm CC-ed on where the person sending the email must have my 'show-as name' in their Address Book as "Brian Skinn", where my email address doesn't appear in the message header.  I *do* find that message if I call .Restrict("Brian Skinn"), but I don't if I call .Restrict() using my actual email address.

    In another email, which was an auto-response from a vendor where they sent it to my email address without including my name, I do find that message with .Restrict([my email address]) but don't find it with .Restrict("Brian Skinn")

    So: this appears to be a really annoying problem if you can't be sure exactly in what form the name you're searching for is going to appear in the To/CC/BCC field.  You might be better off just iterating over the .Items collection and doing a string-search on the .To/.CC/.BCC properties of each item.  You'll have to check each one to make sure it's a MailItem before you try to read .To/.CC/.BCC, though, since other Item types don't have those properties.  If you want to find other items (TaskItems, MeetingItems, etc.) you'll have to check for each type and look at the appropriate Properties within each.

    Tuesday, August 7, 2012 3:28 PM
  • One could use a restriction with multiple conditions to check for, such as an email address or a name. Using a SQL-like restriction one could also use a LIKE clause with % operators to key onto partial strings.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Brian Skinn" <=?utf-8?B?QnJpYW4gU2tpbm4=?=> wrote in message news:2ac9a5fd-fdeb-4039-9a0a-1c5d2b51f1e5...

    I just spent some time fiddling around with the .Restrict function, and it looks like it's sensitive to the form of the email address used to send messages.  In particular, .Restrict will only find the string you put in if it *exactly matches* what's listed in the email header.

    For example, I have one message that I'm CC-ed on where the person sending the email must have my 'show-as name' in their Address Book as "Brian Skinn", where my email address doesn't appear in the message header.  I *do* find that message if I call .Restrict("Brian Skinn"), but I don't if I call .Restrict() using my actual email address.

    In another email, which was an auto-response from a vendor where they sent it to my email address without including my name, I do find that message with .Restrict([my email address]) but don't find it with .Restrict("Brian Skinn")

    So: this appears to be a really annoying problem if you can't be sure exactly in what form the name you're searching for is going to appear in the To/CC/BCC field.  You might be better off just iterating over the ..Items collection and doing a string-search on the .To/.CC/.BCC properties of each item.  You'll have to check each one to make sure it's a MailItem before you try to read .To/.CC/.BCC, though, since other Item types don't have those properties.  If you want to find other items (TaskItems, MeetingItems, etc.) you'll have to check for each type and look at the appropriate Properties within each.


    Ken Slovak MVP - Outlook
    Tuesday, August 7, 2012 3:46 PM
    Moderator
  • True, but one would have to predict all possible permutations of how a particular recipient might appear in order to have a robust .Restrict() call.  Despite the extra work, parsing .To, etc., is going to be much less prone to having messages silently overlooked.

    If I interpret this page correctly, the capability of .Restrict() to handle more complex filter criteria is quite limited except in specific cases.  redgolda, are you using DASL?  If so, then you might be able to use that 'ci_phrasematch' command.  Otherwise, I don't see a way to match subsets when using .Find() or .Restrict()

    Tuesday, August 7, 2012 4:19 PM
  • It's not well documerted, but one can use "@SQL" with normal filtering or restrictions, the DASL syntax can be used with that and not just with content indexing type searches.
     
    For example, this is from the Object Browser Help on restrictions to find "pearls" anywhere in a custom property:
     

    filter = "@SQL=" & Chr(34) & "http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/" & "Mom%27s%20%22Gift%22" & Chr(34) & " like '%pearls%'"


    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Brian Skinn" <=?utf-8?B?QnJpYW4gU2tpbm4=?=> wrote in message news:bb7d4191-778b-43d2-9528-6584c1a0f6ce...

    True, but one would have to predict all possible permutations of how a particular recipient might appear in order to have a robust ..Restrict() call.  Despite the extra work, parsing .To, etc., is going to be much less prone to having messages silently overlooked.

    If I interpret this page correctly, the capability of .Restrict() to handle more complex filter criteria is quite limited except in specific cases.  redgolda, are you using DASL?  If so, then you might be able to use that 'ci_phrasematch' command.  Otherwise, I don't see a way to match subsets when using .Find() or .Restrict()


    Ken Slovak MVP - Outlook
    Tuesday, August 7, 2012 4:54 PM
    Moderator
  • How would one construct a SQL-like query in a VBA call to Items.Restrict to find a subset match in the .To (or .CC or .BCC) property of a MailItem?  I'm having trouble making it work.

    • Edited by Brian Skinn Tuesday, August 7, 2012 5:20 PM
    Tuesday, August 7, 2012 5:16 PM
  • The DASL property tag for To in a Unicode store is "http://schemas.microsoft.com/mapi/proptag/0x0E04001F"
     
    Let's say I want to find "slovak" somewhere in the To field of a mail item.
     
    Dim sFilter As String
    Dim sPropTag As String
     
    sFilter = "@SQL="
     
    sFilter = sFilter & Chr(34) & sPropTag & Chr(34) & " LIKE '%slovak%'"
     
    That would find both "Ken Slovak" and "kenslovak@mvps.org " and any of my other email addresses that have "slovak" in them.
     
    Set filteredItems = colItems.Restrict(sFilter)
     
    One tip that's often helpful, at least if the property is available in the selector, is to construct the filter you want in the Customize View dialog. If you set up the filter you want in the Advanced tab of the dialog you can then go to the SQL tab and copy the filter there into your filter. You still need to massage the quote characters so they're where they need to be, and to add the "@SQL=" clause, but the basics of the filter are constructed for you in that dialog.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Brian Skinn" <=?utf-8?B?QnJpYW4gU2tpbm4=?=> wrote in message news:499d4504-a428-4c52-889c-58a638d955f3...
    How would one construct a SQL-like query in a VBA call to Items.Restrict to find a subset match in the .To (or .CC or .BCC) property of a MailItem?  I'm having trouble making it work.


    Ken Slovak MVP - Outlook
    Tuesday, August 7, 2012 5:37 PM
    Moderator
  • Ken,

    Aha, double quotes around the schema namespace, single quotes and percent signs around the search string.  And, VB single quotes don't need escaping within string literals.  Bleah to poorly documented functions, I say.

    Which 'Customize View' dialog are you referring to in particular? 

    redgolda,

    Use the following:

    .Restrict("@SQL=""http://schemas.microsoft.com/mapi/proptag/0x########"" LIKE '%searchString%'")

    Substitute the desired search-text for searchString ('%alex%'), and the following codes for the ######## depending on which field you want to search:

    • To: 0E04001E
    • Cc: 0E03001E
    • Bcc: 0E02001E
    • Subject: 0037001E
    • Sender's email address: 0C1F001E
    • Sender's name: 0C1A001E

    All eight characters in the codes must be entered, including the leading zeros.  I don't believe it's possible to search email bodies in this fashion.

    The search is insensitive to the case of searchString, as far as I can tell.

    -Brian

    • Marked as answer by redgolda Tuesday, August 14, 2012 6:55 AM
    Tuesday, August 7, 2012 6:11 PM
  • I did say it was poorly documented <g>.
     
    At least it's documented at all, before Outlook 2007 it wasn't documented and only those of us who knew about it used the "@SQL=" type of filtering.
     
    Actually, if you use F1 on Items.Restrict in the Object Browser in the Outlook VBA project you do get information about quoting and single quotes and so on. Using "%" is from SQL syntax where "%" is a wildcard for any zero or more characters, as is the LIKE condition.
     
    For Outlook 2010, go to the View tab. Click View Settings for current view and click the Filter button. Create and copy the filter but don't apply or OK it unless you want the view actually changed.
     
    On any of the string propertiy tags or to be precise the PT_STRING8 or PT_UNICODE properties such as 0E04001E, "1E" means ASCII 8 bit strings and "1F" means Unicode strings.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Brian Skinn" <=?utf-8?B?QnJpYW4gU2tpbm4=?=> wrote in message news:717a4cf4-a94a-4067-aa3b-0337b5887238...

    Ken,

    Aha, double quotes around the schema namespace, single quotes and percent signs around the search string.  And, VB single quotes don't need escaping within string literals.  Bleah to poorly documented functions, I say.

    Which 'Customize View' dialog are you referring to in particular? 

    redgolda,

    Use the following:

    .Restrict("@SQL=""http://schemas.microsoft.com/mapi/proptag/0x########"" LIKE '%searchString%'")

    Substitute the desired search-text for searchString ('%alex%'), and the following codes for the ######## depending on which field you want to search:

    • To: 0E04001E
    • Cc: 0E03001E
    • Bcc: 0E02001E
    • Subject: 0037001E
    • Sender's email address: 0C1F001E
    • Sender's name: 0C1A001E

    All eight characters in the codes must be entered, including the leading zeros.  I don't believe it's possible to search email bodies in this fashion.

    The search is insensitive to the case of searchString, as far as I can tell.

    -Brian


    Ken Slovak MVP - Outlook
    Tuesday, August 7, 2012 6:49 PM
    Moderator
  • Oh, I wasn't trying to say you hadn't already noted the poor documentation, I was just expressing my feelings on the matter.

    My near-complete lack of SQL experience hindered me on % and LIKE.

    I was looking in the wrong place before; I'd tried to set up a Search Folder up and those don't present an SQL tab.

    I found the SQL tab in the 'View > Filter' settings like you indicated & generated a test filter for bcc - the filter ended up with a schema of the form "urn:schemas:calendar:resources" LIKE '%testing%'... Seriously?  'Bcc' is 'calendar:resources'?  Who came up with this?

    I'd known that the two LSB of the MAPI tag were for datatype; it's good to know that there's the option to use Unicode if its needed.

    redgolda, sorry for hijacking your post; Ken, thanks so much for clarifying all this!

    Tuesday, August 7, 2012 7:05 PM
  • thats ok :) i'll try everything tomorrow.

    what if i'm searching for by mail address when the contact is already saved in my address book (so i see his name and not the e-mail address)?
    will i find his mails by searching by mail with the field [Sender's email address: 0C1F001E]?

    Tuesday, August 7, 2012 7:25 PM
  • You should, but make sure to use the entire property tag:
     

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "redgolda" <=?utf-8?B?cmVkZ29sZGE=?=> wrote in message news:2cb9144b-e40e-42a4-b738-ffc4948ed0f7...

    thats ok :) i'll try everything tomorrow.

    what if i'm searching for by mail address when the contact is already saved in my address book (so i see his name and not the e-mail address)?
    will i find his mails by searching by mail with the field [Sender's email address: 0C1F001E]?


    Ken Slovak MVP - Outlook
    Tuesday, August 7, 2012 7:30 PM
    Moderator
  • Nice catch, I like that one. urn:schemas:calendar:resources for Bcc <lol>
     
    In that schema it obviously should be "urn:schemas:httpmail:displaybcc".
     
    Cc is correct in the filter though as "urn:schemas:httpmail:displaycc".
     
    I verified it in the latest version of Outlook 2010, and reported a bug on it with the Outlook product group.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Brian Skinn" <=?utf-8?B?QnJpYW4gU2tpbm4=?=> wrote in message news:efac0b53-7a43-43b5-b09a-9acd8668898a...

    Oh, I wasn't trying to say you hadn't already noted the poor documentation, I was just expressing my feelings on the matter.

    My near-complete lack of SQL experience hindered me on % and LIKE.

    I was looking in the wrong place before; I'd tried to set up a Search Folder up and those don't present an SQL tab.

    I found the SQL tab in the 'View > Filter' settings like you indicated & generated a test filter for bcc - the filter ended up with a schema of the form "urn:schemas:calendar:resources" LIKE '%testing%'... Seriously?  'Bcc' is 'calendar:resources'?  Who came up with this?

    I'd known that the two LSB of the MAPI tag were for datatype; it's good to know that there's the option to use Unicode if its needed.

    redgolda, sorry for hijacking your post; Ken, thanks so much for clarifying all this!


    Ken Slovak MVP - Outlook
    Tuesday, August 7, 2012 7:30 PM
    Moderator
  • It probably won't matter -- I believe incoming emails always only show what the sender's email application put into the email.  That's why it's so annoying, because you have little to no control over how everyone else in the world has configured their contact information.  At least the SQL 'LIKE' is case-insensitive!
    Tuesday, August 7, 2012 7:51 PM
  • Ken,

    Would it make sense just to always use Unicode? Or are there subtle ways that Unicode can be funny & it would be better to use ASCII unless there's a specific reason to expect, e.g., Asian characters or modified, non-ASCII Latin characters?

    Tuesday, August 7, 2012 7:53 PM
  • I mostly use the Unicode tag these days, but you'll get what's available no matter which tag you use. You'd usually get a fallback if necessary.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Brian Skinn" <=?utf-8?B?QnJpYW4gU2tpbm4=?=> wrote in message news:f858335c-fe21-4f95-8470-0c24a468f3e3...

    Ken,

    Would it make sense just to always use Unicode? Or are there subtle ways that Unicode can be funny & it would be better to use ASCII unless there's a specific reason to expect, e.g., Asian characters or modified, non-ASCII Latin characters?


    Ken Slovak MVP - Outlook
    Tuesday, August 7, 2012 8:56 PM
    Moderator
  • Is there a list somewhere of the property names in the "urn:schemas:..." format?  All I could find was this list of the MAPI proptags.  This page talks about the "urn:schemas:..." subnamespace, but doesn't appear to link to any sort of comprehensive list of property names.
    • Edited by Brian Skinn Wednesday, August 8, 2012 1:12 PM Added sentence
    Wednesday, August 8, 2012 1:09 PM
  • I've been reminded that since meeting invitations use Bcc for resources that "urn:schemas:calendar:resources" is actually functionally the equivalent of the more likely-looking property schemas for Bcc. It does actually work correctly with that DASL tag, although it definitely looks weird.
     
    If you're interested in MAPI concepts and tags and so on, the most complete reference these days since the Outlook team took over MAPI from Exchange is http://msdn.microsoft.com/en-us/library/cc765775.aspx

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Brian Skinn" <=?utf-8?B?QnJpYW4gU2tpbm4=?=> wrote in message news:445b7a4c-3220-48f4-aeb0-32731100129f...
    Is there a list somewhere of the property names in the "urn:schemas:..." format?  All I could find was this list of the MAPI proptags.  This page talks about the "urn:schemas:..." subnamespace, but doesn't appear to link to any sort of comprehensive list of property names.

    Ken Slovak MVP - Outlook
    Wednesday, August 8, 2012 2:29 PM
    Moderator