views:

99

answers:

4

I am able to open Lotus notes api using Perl, without errors, also I can get list of views that includes Inbox, but when I try to read messages from that view it appears empty? What might I be doing wrong? (in fact it seems like something might of changed on notes side as this code used to work before)

Result of code below: NAME of View is: ($Inbox) has count of: 0 etc.

CODE:

use Win32::OLE;
my $Notes = Win32::OLE->new('Notes.NotesSession')
or die "Cannot start Lotus Notes Session object.\n";
my $database = $Notes->GetDatabase("",'mail\VIMM.nsf');
$database->OpenMail;
my $array_ref = $database->{Views};
foreach my $view (@$array_ref) {
    my $name = $view->{Name};
    print "NAME of View is: $name ";
    $view = $database->GetView($name);
    print "has count of: ", $view->{entryCount}, "\n";
}
+1  A: 

I believe it is spelled "EntryCount"?

Also, I recommend "use strict" and "use warnings".

runrig
Thanks, interestingly I got numbers above 0 for few of the folders, will test now.
Ville M
+1  A: 

Per runrig's comment, EntryCount is an attribute, so I believe you need: $view->{entryCount}

Ed Schembor
so that did not seem to make difference, see comment above, any other thoughts?
Ville M
+1  A: 

Try checking Win32::OLE::LastError() messages. You can do this explicitly with a sub like:

sub w32_ok {
    if (my $error = Win32::OLE::LastError()) {
        print "Win32::OLE Error!  Got: $error";
    }
}

Or, have it croak errors, like:

Win32::OLE->Option( Warn => 3 ); # will now croak on errors.

It may be having problems accessing the data you want.

Robert P
Thanks for the tip, I added that, and it complained about "$database->OpenMail;" saying that DB is already open so I removed that line, no other change, but it doesn't appear there is any other error.
Ville M
+1  A: 

Is the mailbox open to all users? You could try setting the -Default- access to Manager and grant it all available roles, just to make sure it's not a security issue preventing the documents from being seen.

Ken Pespisa
How do I do that, I tried going to notes client and in security I checked all check boxes for "no signature" and for "default user", is there something else? How would I be able to tell if it's a security issue?
Ville M
You need to change the ACL. Go to File > Database > Access Control. Give the -Default- user Manager access to the database and select all the roles in the lower right corner of the dialog. That will rule out security being an issue. BTW, do you know who you are logging in as via this script?
Ken Pespisa
That's it, this is probably the issue. did not realize that since I could read the views I couldn't read the actual entries in there, looks like I don't have enough access to change default roles or access, how do I change it so that in my code I log in as myself rather than default user?
Ville M
I don't know Perl, but I know the method is "Initialize" and you can pass a password. The code will use the Notes ID specified in the notes.ini on the current machine, specifically what's assigned as the KeyFileName. So I think the code would be $notes->Initialize("yourpassword")
Ken Pespisa
Maybe security isn't the problem after all. I added that line, tried it both before and after opening my NSF file, but unfortunately it did not help. Same result still, most 0s in the entrycounts. Also interestingly seems like the notes API examples they don't usually do this initialize steps. Anyways, any other thoughts what might be the problem?
Ville M
I also added print $Notes->UserName; and it prints my correct username.
Ville M
Ok, so you are definitely logged in as you, and assuming you can see the documents when you open the database, there's no reason you shouldn't also be able to see them from code. Perhaps it's a bug? There's other ways to look at the contents of a view. Maybe try using the $view->GetFirstDocument() method, and make sure it is valid (you could get the document's NoteId property to check that). If that does work, you could iterate all documents in the view using GetNextDocument(doc) in a loop, and just count them up within the loop.
Ken Pespisa
Maybe this is a bug as you say, I added this: $view = $database->GetView('($Inbox)');$doc = $view->GetFirstDocument();print $doc->{IsValid}; and it results in error "Use of uninitialized value in print"
Ville M
What happens if you try getting documents in the All Documents view? $database->GetView('($All)'); Then get the first document and try print $doc->{NoteID}; This is really baffling.
Ken Pespisa
I agree, sure is, baffling is the right word:$view = $database->GetView('($All)');$doc = $view->GetFirstDocument();print $doc->{NoteID};results in error: "Use of uninitialized value in print"
Ville M
Just out of curiousity, can you try pointing this same script to other Notes databases? Maybe a local one you create? I'm just thinking it would be good to rule out the problem being something with that particular database.
Ken Pespisa
That's it, it does appear to be related to the "default" mail database, I just opened the "archive" email database and there everything works: 4949 docs Any ideas on what do you think could be going wrong with the default mail database?
Ville M
Besides things we tried, I still wonder if there are some Reader fields set within the documents. If I remember correctly, the main areas of security in Notes are at the server in the server configuation docs, on the database itself in the ACL, and on the documents themselves using author and reader fields. It seems you've moved passed the first two hurdles, but the last one could be the culprit. Other ideas: Are the emails encrypted? I'm not sure if you can access encrypted emails via COM. Is the archive email database on the same server? If not, the server may be the issue.
Ken Pespisa