WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

ADSI LDAP CDO
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Exchange/Outlook Folders via Winbatch and CDO

Keywords: 	 Exchange/Outlook Folders CDO

;       script by Jay Alverson, 10/4/2000
;
;       this script uses winbatch and Collaborative Data Objects (CDO)
;       to search the MS Exchange 5.5 infostores for my email account.
;       in Outlook you can attach to one or more mailboxes (infostores)
;       when you use the application. this script searches for my personal
;       mailbox, then enumerates the top-level folders underneath. since
;       you can have subfolders & subfolders under them (ad nauseum) so
;       you'll have to code your own subsearches. nice thing is they're
;       all the same, you just need to allocate new objects/handles for
;       items. another good thing is that the .COUNT property seems to
;       work on these objects!
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;       in addition the script will move a mail message whose SUBJECT
;       contains the string "Undeliverable" to the DELETED ITEMS folder,
;       via retrieving the DESTINATION folder's ID, which is a huge
;       string.
;
;       THIS SCRIPT MAY NOT WORK IF YOU'VE RENAMED OR MOVED THE FOLDERS
;       in this example. my DELETED ITEMS folder is "above" my INBOX.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;       you can alter this script to look thru PUBLIC FOLDERS, just
;       change the STRINDEXWILD statement to reflect this, then move
;       thru the subfolders, etc, etc.
;
;       also notice the end of the script:  cdoSession.logoff
;
;       I'm using winbatch 2000c and CDO.DLL (version 5.5.2448.0,
;       Collaboration Data Objects 1.21 for Windows NT) which you
;       can download from the Microsoft Web Site.
;
;       handy website...
;       http://msdn.microsoft.com/library/psdk/cdo/_olemsg_object_collections.htm
;       
;       setup the profile to logon to...
strProfileInfo = strcat("profilename", @lf, "servername")
;       open the mapi session object and logon...
cdoSession = Objectopen("MAPI.Session")
cdoSession.Logon( , , @false, @false, , @True, strProfileInfo)
;       allocate the infostores object...
cdoInfoStores = cdoSession.InfoStores
;       init the display var...
infostoredata = ""
;       add the infostores count...
infostoredata = strcat(infostoredata, @crlf, "Number of Info Stores found:", cdoInfoStores.count)
;message("Info Stores", cdoInfoStores.count)
;       loop thru the infostores 1 by 1...
for is = 1 to cdoInfoStores.count
        item = cdoInfoStores.item(is)
;       message("Info Store #%is%", item.name)
;       look for my mailbox...
        if strindexwild(item.name, "Mailbox - Alverson Jay W", 1) > 0
        ;       we found it, now get a list of folders...
                dname = item.name       ; set display name...
                ;       add the mailbox name to the display data...
                infostoredata = strcat(infostoredata, @crlf, dname)
                ;       allocate an object for my mailbox...
                myMailbox = item
                ;       set the root folder object...
                myFolder = myMailbox.RootFolder
                ;       allocate the object for all folders...
                myFolderlist = myFolder.Folders
;               message("Folders for %dname%", myFolderlist.count)
;               add the folder count to the display data...
                infostoredata = strcat(infostoredata, @crlf, "Number Mailbox Folders found:",@tab, myFolderlist.count, @crlf)
                ;       loop thru the top-level folders one by one...
                for fld = 1 to myFolderlist.count
                        myFolderItem = myFolderlist.item(fld)
                        ;       look for only the INBOX or the DELETED ITEMS...
                        if strindexwild(myFolderItem.name, "Inbox", 1) > 0 || strindexwild(myFolderItem.name, "Deleted Items", 1) > 0
        ;                       message("Folder Name", myFolderItem.name)
                                if strindexwild(myFolderItem.name, "Inbox", 1) > 0
        ;                       add the folder name to the display data...
                                infostoredata = strcat(infostoredata, @crlf, "Folder found:", @tab,myFolderItem.name, @crlf, "Folder ID: ", myFolderItem.id)
                                ; allocate the messages in the folder to an object...
                                msgInFolder = myFolderItem.messages
                                ;       get a count in each folder...
                                infostoredata = strcat(infostoredata, @crlf, "Messages in Folder: ", msgInFolder.count)
;                               now look at each message, first allocate the object...
                                for ibi = 1 to msgInFolder.count
                                        msgitem = msgInFolder.item(ibi)
                                        if strindexwild(msgitem.subject, "Undeliverable", 1) > 0
                                                message("Found!", msgitem.subject)
                                                infostoredata = strcat(infostoredata, @crlf, "Messages Subject: ", @tab, msgitem.subject)
                                                ;       now move the undeliverable to the deleted items folder...
                                                msgitem.moveto(delItemFolderID)
                                        endif
                                next ; message in folder...
                                else ;  get the deleted items folder ID...
                                        delItemFolderID = myFolderItem.id
                                        infostoredata = strcat(infostoredata, @crlf, "Deleted Items Folder ID: ", @tab, myFolderItem.id)
                                endif ; inbox information check...
                        endif
                next    ; folder in collection...
        endif
next    ; infostore...
;       logoff, cleanup and display the data...
cdoSession.logoff
objectclose(cdoSession)
message("CDO Info Stores", infostoredata)
exit

Article ID:   W14678
Filename:   Search Exchange-Outlook Infostores with CDO.txt
File Created: 2000:10:10:10:18:32
Last Updated: 2000:10:10:10:18:32