Ruby iterating over Exchange Mailboxes

J

Jeff Miller

Hello,
I have been hitting my head against the wall for hours now. For the
life of me, I can't figure out whats wrong with my script... I have a
test script that interacts with CDO to access Microsoft Exchange, as
follows:

require 'win32ole'

#~ START MAPI/CDO SESSION
session = WIN32OLE.new('Mapi.session')
session.logon("username", "password")

#~ GET A LIST OF MAILBOXES TO ITERATE OVER
address_list = session.GetAddressList(0)
address_entry = address_list.AddressEntries

#~ INITIATE NEW MAPI SESSION (FOR DYNAMIC LOGONS)
newsession = WIN32OLE.new('Mapi.session')

#~ ITERATE OVER ALL MAILBOXES
address_entry.each do |row|
profileInfo = "EX" + "\n" + row.Name
newsession.logon("", "", "FALSE", "TRUE", "0", "TRUE", profileInfo)

#~ EXCEPTION HANDLING
begin
contacts_folder = newsession.GetDefaultFolder(5)
puts newsession.CurrentUser.Name
rescue Exception => blah
puts "DISABLED"
puts blah.inspect
ensure
newsession.logoff

end
end

session.Logoff

Basically, the error comes out of the exception handling portion. When I
comment it out and put "puts newsession.CurrentUser.Name" it gives me
what I want - which is the script accessing every mailbox on Exchange.
The error handling says that if GetDefaultFolder(5) (which is the
Contacts Folder in Outlook) doesn't exist, then that user is disabled,
so skip to the next user. For some reason, with the error handling
section in there, it never outputs consistent data. It could list 5 or 6
users, then, without changing anything and just running it again, it'll
give me 100 users. The message it gives me is as follows:

test_mapisession.rb:42: [BUG] Segmentation fault
ruby 1.8.6 (2007-09-24) [i386-mswin32]

This application has requested the Runtime to terminate it in an unusual
way.
Please contact the application's support team for more information.

line 42 of my code is the "newsession.logoff" that is in the ensure
clause of the error handling statement. Does anybody know what is going
on? I have never encountered a Segmentation fault... I am lost on this,
so any and all help is appreciated!

Thanks!!!
- Jeff Miller
 
J

Jeff Miller

Hello everybody,
I just got this recommendation from a friend:

"Exchange has a limit of 250 open RPC channels, so you need to release
objects as you use them or you'll run out of channels. You'll probably
have to dig a little to find out whether Ruby releases objects
immediately or, like .NET, in its own sweet time and whether it can be
forced to release immediately."

Thus, does anybody know how I can force release of an object?

Thanks!!
- Jeff Miller
 
J

Jano Svitok

Hello everybody,
I just got this recommendation from a friend:

"Exchange has a limit of 250 open RPC channels, so you need to release
objects as you use them or you'll run out of channels. You'll probably
have to dig a little to find out whether Ruby releases objects
immediately or, like .NET, in its own sweet time and whether it can be
forced to release immediately."

Thus, does anybody know how I can force release of an object?

try WIN32OLE#ole_free:
http://ruby-doc.org/stdlib/libdoc/win32ole/rdoc/classes/WIN32OLE.html#M009643

most probably:
some_object.ole_free
some_object = nil

warning: I have not tried this.

Jano
 
J

Jano Svitok

Thanks for the reply, but I've tried those multiple times... still no
luck

You may try running your script under windbg to see where the crash happens
and/or what's the problem (although you'll need debug symbols to see
anything more useful).

J.
 
A

Alex Krenvalk

I have been working for some months with some kinds of programs which
might resolve any problem just like this. One of the best to my mind is
the next utility, which is able to show how it recovers mailboxes bigger
than 2gb in Exchange 2003 and etc. What is more this tool is quite
reliable and easy to use -
http://www.mailboxexchangerecovery.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top