views:

444

answers:

4

Provided that I have the mail file name and the server, how do I retrieve the fully qualified name of the user it corresponds to in the form "CN=xxx/O=yyy" using LotusScript?

To start with, I have the user's username - the part before @ in the email: i.e. [email protected]

I also know server, on which this user is registered, so I use Registration.GetUserInfo like this:

Dim reg as New NotesRegistration
reg.RegistrationServer = "CN=myserver/O=mydomain"
Call reg.GetUserInfo("user1", mailserver$, mailfile$)

The question is: how out of this data I can get the full name of the user?

+1  A: 

If you have the mail file name, why not do a lookup into the NAB using that as your key and get the full name that way?

Jonesy
+2  A: 

Here's a quick implementation of Jonesys suggestion:

Function getMailFileUser(mailserver As String, mailfile As String) As String
    On Error Goto errorthrower  
    Dim session As New notessession

    Dim dd As NotesDatabase
    Forall candidate_dd In session.AddressBooks
        If candidate_dd.Server<>"" And candidate_dd.IsPublicAddressBook Then
            Set dd = candidate_dd
            Exit Forall
        End If
    End Forall 
    If dd Is Nothing Then Error 1978,"Failed to find Domino Directory"
    If Not dd.IsOpen Then Call dd.Open("","")


    Dim userdocs As NotesDocumentCollection
    Set userdocs = dd.Search({form="Person" & }& _
    {@name([CANONICALIZE];MailServer)=@name([CANONICALIZE];"} & mailserver & {") & } &_
    {MailFile="} & mailfile & {"},Nothing,1)

    Dim userdoc As NotesDocument
    Set userdoc = userdocs.GetFirstDocument
    If Not userdoc Is Nothing Then
        getMailFileUser = userdoc.FullName(0)       
    Else
        getMailFileUser=""
    End If

    Exit Function
ErrorThrower:
    Error Err, Error & Chr(13) + "Module: " & Cstr( Getthreadinfo(1) ) & ", Line: " & Cstr( Erl )
End Function

A few words of caution:

  • CANONICALIZE picks its values from the current ID, not the domino directory - the input mailserver must be in either abbreviated or canonicalized form for this to work.
  • The MailFile field may or may not include the .nsf extension.
  • I don't think the file name is case sensitive on Windows, but it might be on other platforms.

If you need to do these lookups frequently, a computed lookup table or a view in the Domino Directory is probably the most efficient solution.

Anders Lindahl
+1 for the good code. I did not use it, but still, this is a good example. Thanks.
Sunny
A: 

If you have the internet address you can just use the NotesName class.

Dim s As New NotesSession
Dim userName As NotesName
Dim canonicalName as String

Set userName = s.CreateName("[email protected]")
'You can use the previous line or the next line to get the NotesName object
'Set userName = new NotesName("[email protected]")

canonicalName = userName.Canonical
Carlos
This doesn't work for me. MessageBox(userName.Canonical) displays the email.
Sunny
Instantiating a NotesName with just an internet address won't help here.
Ben Poole
A: 

I ended up with this solution (as I know which is the AddressBook server for the user):

macro$ = { @DbLookup( "" ; "} & regServer & _
         {" : "names.nsf" ; "($Users)" ; "} & shortName & {" ; "FullName" ) }

Dim namelist As Variant

namelist = Evaluate ( macro$ )

commonName = namelist(0)
Sunny