• Sign in
 
  •  
  • MSDN Blogs
  • Microsoft Blog Images
  • More ...

  • About
  • Email Blog Author
  • RSS for posts
  • Atom
  • RSS for comments
    • OK
  • CDO (25)
  • Code Snippet (43)
  • Custom Providers (17)
  • Debugging (7)
  • DevMsgTeam (301)
  • Documentation (109)
  • DST (8)
  • EWS (7)
  • Exchange (109)
  • Gotchas (97)
  • Hotfix (28)
  • MAPI (240)
  • MAPI Download (54)
  • MFCMAPI (101)
  • MSDN (59)
  • Non Dev (11)
  • OOM (17)
  • Outlook (171)
  • Outlook 2007 Auxiliary Reference (45)
  • Outlook Integration API (12)
  • Protocol Docs (20)
  • PST/OST (23)
  • Referrals (8)
  • Vista (12)
  • WrapPST (18)
Links:
  • Download MFCMAPI
  • MFCMAPI on Facebook
  • Troubleshooting Outlook Crashes
  • Office Update Center
  • Developer Messaging Team Blog
This site is provided "AS IS" with no warranties, and confers no rights. Use of included code samples are subject to the terms specified in the Terms of Use.
Archives
  • May 2013 (3)
  • April 2013 (1)
  • March 2013 (2)
  • February 2013 (2)
  • January 2013 (2)
  • December 2012 (4)
  • November 2012 (2)
  • October 2012 (2)
  • September 2012 (1)
  • August 2012 (3)
  • June 2012 (2)
  • May 2012 (1)
  • April 2012 (3)
  • March 2012 (3)
  • February 2012 (3)
  • January 2012 (1)
  • December 2011 (3)
  • November 2011 (1)
  • October 2011 (3)
  • September 2011 (1)
  • August 2011 (1)
  • July 2011 (4)
  • June 2011 (3)
  • May 2011 (3)
  • April 2011 (3)
  • March 2011 (5)
  • February 2011 (1)
  • January 2011 (2)
  • December 2010 (1)
  • November 2010 (4)
  • October 2010 (1)
  • September 2010 (3)
  • August 2010 (5)
  • July 2010 (3)
  • June 2010 (3)
  • May 2010 (1)
  • April 2010 (3)
  • March 2010 (3)
  • February 2010 (3)
  • January 2010 (2)
  • December 2009 (3)
  • November 2009 (5)
  • October 2009 (4)
  • September 2009 (5)
  • August 2009 (5)
  • July 2009 (11)
  • June 2009 (6)
  • May 2009 (5)
  • April 2009 (3)
  • March 2009 (18)
  • February 2009 (10)
  • January 2009 (3)
  • December 2008 (2)
  • November 2008 (2)
  • October 2008 (5)
  • September 2008 (4)
  • August 2008 (10)
  • July 2008 (6)
  • June 2008 (8)
  • May 2008 (2)
  • April 2008 (4)
  • March 2008 (2)
  • February 2008 (2)
  • January 2008 (5)
  • December 2007 (3)
  • November 2007 (2)
  • October 2007 (3)
  • September 2007 (1)
  • August 2007 (4)
  • July 2007 (5)
  • June 2007 (3)
  • May 2007 (4)
  • April 2007 (1)
  • March 2007 (6)
  • February 2007 (3)
  • January 2007 (2)
  • December 2006 (4)
  • November 2006 (3)
  • October 2006 (1)
  • August 2006 (1)
  • June 2006 (5)
  • May 2006 (5)
  • December 2005 (1)
  • November 2005 (4)
  • October 2005 (2)
  • September 2005 (1)
  • April 2005 (3)
  • December 2004 (2)
  • September 2004 (2)
  • August 2004 (3)
  • July 2004 (3)
Blogs I Read
  • Exchange

  • Raymond Chen [MSFT]

  • Larry Osterman [MSFT]

  • Peter David

  • Aaron Margosis [MSFT]

  • Jason Johnston [MSFT]

  • Matt Stehle (MSFT)

  • Patrick Creehan [MSFT]

  • Ryan Gregg [MSFT]

    Outlook PM
  • WebDav 101

    Dan Bagley (MSFT)
  • Dave Vespa [MSFT]

  • Randy Topken

    Outlook EE

October, 2008

MSDN Blogs > SGriffin's MAPI Internals > October, 2008
  • Subscribe via RSS
Sort by: Most Recent | Most Views | Most Comments
Excerpt View | Full Post View
  • SGriffin's MAPI Internals

    When I Say Shutdown, I Mean Shut. Down.

    Posted over 5 years ago
    by Stephen Griffin - MSFT
    • 3 Comments

    Ryan posted an article about some changes we're making in Outlook 2007 SP2. The gist is we're changing Outlook's shutdown behavior to always shutdown regardless of whether there are other running applications using the Outlook Object Model. He's looking for feedback on the logic change, so be sure to send him your comments.

  • SGriffin's MAPI Internals

    Get The OOF Out Of Here

    Posted over 5 years ago
    by Stephen Griffin - MSFT
    • 1 Comments

    Dan asked if I could post some CDO sample code he was working on. This sample script demonstrates a few interesting things:

    • Dynamic session creation
    • Accessing the associated contents table of a folder using HiddenMessages
    • Looping backwards through a collection so deletion doesn't affect the cursor
    • Accessing properties documented in the Protocol Docs (PidTagRuleMsgProvider and PidTagRuleMsgName) using CDO's Fields collection

    Ultimately, what this sample does is delete all Out Of Office related messages (rules and templates), and switch off Out Of Office. Be careful running this sample! It doesn't back up anything before it deletes the OOF messages. So be certain that's what you really want to do before you go running this sample against a production mailbox.

    If you want to run this code on an Outlook 2007 machine, you'll need to have CDO installed: CDO Download. If you want to run it without any version of Outlook installed, you can use the MAPI/CDO download: MAPI/CDO Download.

    Enjoy!

     

    '-----------------------------------------------------------------------------------------
    ' Deloof.vbs - This sample shows how to walk through hidden items in a mailbox and delete
    '   the OOF templates and turn off OOF. 
    ' 
    ' This is a sample and is not intended to be used in a production environment.
    ' This script needs to be run from a 32 bit command line using cscript on a box with CDO 1.21 installed.
    ' The account running the code needs permission to the mailbox it will access.
    '
    '  9/19/08 danba    - changed sample to include 6 message class tests.
    '  9/23/08 danba    - changed logic for TDX OOF Rules - PidTagRuleMsgName may not always be set.
    ' 10/24/08 sgriffin - minor scrub to formatting
    '-----------------------------------------------------------------------------------------
     
    Private Function RunIt(sServerName, sMailbox)  'As Boolean
        Dim objsession            ' MAPI.Session
        Dim objInbox              ' MAPI.Folder
        Dim objHidden             ' MAPI.Messages
        Dim objMsgFilter          ' MAPI.MessageFilter
        Dim objOneMessage         ' MAPI.Message
        Dim sMessageClass         ' String  ' Message Class of rule
        Dim s_ptagRuleMsgProvider ' String  ' Provider of rule
        Dim s_ptagRuleMsgName     ' String  ' Rule name
        Dim sFoundMessage         ' String  ' Holds a message describing what was found.
        Dim bDelete               ' Boolean ' Used to indicate if an item should be deleted.
        Dim iHidden               ' Integer ' Use to loop through hidden items
     
        wscript.echo "-------------------------"
        wscript.echo "Time: " & Now
        Set objsession = CreateObject("MAPI.session")
     
        objsession.Logon "", "", False, False, 0, True, sServerName & vbLf & sMailbox
        wscript.echo "Login completed on mailbox " & sMailbox & " on server" & sServerName
     
        Set objInbox = objsession.Inbox
        wscript.echo "Looking at the Inbox"
     
        Set objHidden = objInbox.HiddenMessages
        wscript.echo "Looking at the Hidden Items"
     
        ' --- Now we have the Hidden messages Set. Let's work thru the Hidden Messages and delete the 'oof items'
        For iHidden = objHidden.Count To 1 Step -1    ' Walk Hidden backward one time
            bDelete = false
            sDeleteMessage = ""
     
            Set objOneMessage = objHidden.Item(iHidden)
            sMessageClass = objOneMessage.Type
     
            On Error Resume Next
            s_ptagRuleMsgProvider = ""
            s_ptagRuleMsgName = ""
            s_ptagRuleMsgProvider = objOneMessage.Fields(&H65EB001E) ' PidTagRuleMsgProvider
            s_ptagRuleMsgName = objOneMessage.Fields(&H65EC001E)     ' PidTagRuleMsgName
     
            sFoundMessage = "Class: """ & sMessageClass & """"
            if s_ptagRuleMsgName     <> "" Then sFoundMessage = sFoundMessage & " Name: """     & s_ptagRuleMsgName     & """"
            if s_ptagRuleMsgProvider <> "" Then sFoundMessage = sFoundMessage & " Provider: """ & s_ptagRuleMsgProvider & """"
     
            ' TODO: comment out line below if you don't wish to what was found
            Wscript.echo "  Found:    " & sFoundMessage
     
            If sMessageClass = "IPM.Rule.Message" Then
                If s_ptagRuleMsgProvider = "Microsoft Exchange OOF Assistant" AND _
                  s_ptagRuleMsgName = "Microsoft.Exchange.OOF.InternalSenders.Global" Then
                    bDelete = true
                End If
     
                If s_ptagRuleMsgProvider = "MSFT:TDX OOF Rules" Then
                    bDelete = true
                End If
     
                If s_ptagRuleMsgProvider = "Microsoft Exchange OOF Assistant" AND _
                  s_ptagRuleMsgName = "Microsoft.Exchange.OOF.AllExternalSenders.Global" Then
                    bDelete = true
                End If
            End If
     
            If sMessageClass = "IPM.Note.Rules.OofTemplate.Microsoft" Then
                bDelete = true
            End If
     
            If sMessageClass = "IPM.Note.Rules.ExternalOofTemplate.Microsoft" Then
                bDelete = true
            End If
     
            If sMessageClass = "IPM.ExtendedRule.Message" Then
                If s_ptagRuleMsgProvider = "Microsoft Exchange OOF Assistant" AND _
                  s_ptagRuleMsgName = "Microsoft.Exchange.OOF.KnownExternalSenders.Global" Then
                    bDelete = true
                End If
            End If
     
            If bDelete = true  Then
                objHidden.Item(iHidden).Delete     ' TODO: Comment-out if testing
                wscript.echo "  Deleted:  " & sFoundMessage
            End If
     
        Next
     
        objsession.OutOfOffice = 0 ' Turn off OOF  ' TODO: Comment-out if testing
     
        objsession.Logoff
     
        Set objOneMessage = Nothing
        Set objInbox = Nothing
     
        Set objsession = Nothing
     
        wscript.echo "Finished"
        wscript.echo "-------------------------"
     
        RunIt = True
     
        Return
    End Function
     
     
    Dim bRet
     
    If Wscript.Arguments.Count = 2 Then
        sServerName = Wscript.Arguments(0)
        sMailbox = Wscript.Arguments(1)
        bRet = RunIt(sServerName, sMailbox)
    Else
        Wscript.Echo "deloof.vbs usage: deloof.vbs <Exchange Server Name> <Mail Box>"
        Wscript.Echo "example: cscript deloof.vbs MyServer somebody@contoso.com"
    End If
  • SGriffin's MAPI Internals

    October 2008 Release of MFCMAPI

    Posted over 5 years ago
    by Stephen Griffin - MSFT
    • 0 Comments

    The October 2008 Release (build 6.0.0.1009) is live: http://www.codeplex.com/MFCMAPI

    Better late than never right? I've been trying to refresh MFCMAPI every two months, but wasn't able to devote the time to it I would have liked with all the work I'm doing on the MAPI documentation refresh. I did need to get this release out the door though since the MAPI docs will be depending on it. This release is all about cleaning up the code. It's been a long time since I went through the whole project and got all nitpicky about comments and whitespace. :)

    Which is not to say I didn't get some nice bug fixes and features added. Here's a partial change list - see the Issue Tracker on Codeplex for more details, or look at the code:

    • Square boxes in list controls: Smart View really exposed this one - carriage returns in the parsed data were showing as boxes in the lists. So now they're scrubbed out, making Smart View easier to read
    • PR_BODY looks empty: When displaying an edit dialog for PR_BODY, there is some strangeness that caused the text to be highlighted and the control scrolled all the way to the end. This made it look like the body was missing! I fixed it so nothing's highlighted and the cursor's at the beginning.
    • PR_ENTRYID: Smart View parses entry ID structures now!
    • Dead code removal, refactoring, and general cleanup: The bulk of the changes are focused here. The code should be much easier to read now, especially now that class data visibility is strictly enforced.

    Enjoy.

  • SGriffin's MAPI Internals

    Rewriting the From Address in Exchange 2007

    Posted over 5 years ago
    by Stephen Griffin - MSFT
    • 0 Comments

    So - we've got customers who had been using the Exchange 2007 Transport Agent's OnRoutedMessage event as a place to rewrite From addresses. This broke in Exchange 2007 SP1 due to some tweaks we made to the transport pipeline to solve a variety of other issues. We've got a fix for this now in Exchange 2007 SP1 Rollup 4, which just released today:

    http://www.microsoft.com/downloads/details.aspx?FamilyId=8B492ED2-EA92-412F-A852-3AA1C58D9499&displaylang=en

    http://support.microsoft.com/?kbid=952580

    RU4 introduces a new event: OnCategorizedMessage. This event is at the right place in the pipeline to do your From address rewriting. Enjoy!

  • SGriffin's MAPI Internals

    Did I Send That?

    Posted over 5 years ago
    by Stephen Griffin - MSFT
    • 5 Comments

    [This is now documented here: http://msdn.microsoft.com/en-us/library/ff960604.aspx ]

    We had a customer here who wondered why messages imported into MAPI using MIMEToMAPI always appeared as draft messages. This is because the default value of PR_MESSAGE_FLAGS includes the MSGFLAG_UNSENT flag. Now - if you know you want your messages to not appear as drafts, the thing to do here is to clear the MSGFLAG_UNSENT flag before saving the message.

    But what if you're exporting messages from mailbox using MAPIToMIMEStm and importing them using MIMEToMAPI, and want to preserve the sent/unsent state across this conversion? One thing you could do is read the state during the export, save it off somewhere (perhaps as a header in the EML file), then use it to determine if the flag needs to be cleared.

    Doable - but a bit of extra work. Turns out there's  flag you can use in those functions that has nearly the same effect: CCSF_EMBEDDED_MESSAGE

    Here's the documentation on the flag:

    Flag value:

    #define CCSF_EMBEDDED_MESSAGE 0x8000 // sent/unsent information is persisted in X-Unsent

    IConverterSession::MAPIToMIMEStm

    When CCSF_EMBEDDED_MESSAGE is set, if PR_MESSAGE_FLAGS has the MSGFLAG_UNSENT flag set, add an X-Unsent header to the MIME message with a value of 1

    IConverterSession::MIMEToMAPI

    When CCSF_EMBEDDED_MESSAGE is set, the resultant MAPI message will have MSGFLAG_READ set in PR_MESSAGE_FLAGS. In addition, if an X-Unsent header is found with a value of 1, the MSGFLAG_UNSENT flag is removed from PR_MESSAGE_FLAGS.

    Remarks

    This flag may be used in Outlook 2003 and higher. The name of this flag reflects the way it originally was used, as a way to deal with embedded messages. It is no longer used in this fashion. If the side effect of setting MSGFLAG_READ is not desired, this flag should not be used. If this flag is not set, MIMEToMAPI will ignore any value in X-Unsent and MSGFLAG_UNSENT will be set in PR_MESSAGE_FLAGS. MAPIToMIMEStm will not write the X-Unsent header at all if the MSGFLAG_UNSENT flag is not set in PR_MESSAGE_FLAGS.

Page 1 of 1 (5 items)
  • © 2013 Microsoft Corporation.
  • Terms of Use
  • Trademarks
  • Privacy & Cookies
  • Report Abuse
  • 5.6.426.415