Big Data/Analytics Zone is brought to you in partnership with:
DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Outlook - Messages To Archive

01.04.2011
| 5279 views |
  • submit to reddit
        Deleted Items = mapi.GetDefaultFolder(3)
Outbox = mapi.GetDefaultFolder(4)
Sent Mail = mapi.GetDefaultFolder(5)
Inbox = mapi.GetDefaultFolder(6)
Calendar = mapi.GetDefaultFolder(9)
Contacts = mapi.GetDefaultFolder(10)
Journal = mapi.GetDefaultFolder(11)
Notes = mapi.GetDefaultFolder(12)
Tasks = mapi.GetDefaultFolder(13)
Drafts = mapi.GetDefaultFolder(16)
All Public Folders = mapi.GetDefaultFolder(18)
Conflicts = mapi.GetDefaultFolder(19)
SyncIssues = mapi.GetDefaultFolder(20)
Local Failures = mapi.GetDefaultFolder(21)
Server Failures = mapi.GetDefaultFolder(22)
Junk = mapi.GetDefaultFolder(23)

#move all 2010 messages from inbox to personal folders "Old Inbox 2010"

require 'win32ole'
outlook = WIN32OLE.new('Outlook.Application')
mapi = outlook.GetNameSpace('MAPI')
#inbox
inbox = mapi.GetDefaultFolder(6)

#personal folders
personal_folders = mapi.Folders.Item('Personal_folder')

#subfolder old inbox 2010 under personal folders
old_inbox = personal_folders.Folders.Item('Old Inbox 2011')

#all items that are older than 1.1.2011 move to archive
inbox.Items.Count.downto(1) do |i|
         message = inbox.Items(i)
         if message.CreationTime < "2011/01/01 00:00:00"
		message.Move(old_inbox)
         end
end