Monday, February 4, 2013

Lotus Script for Extract the Mails from Mail DB (i.e sending and receiving to ther domains)

Sub Initialize
 Dim session As New NotesSession
 Dim curdb As NotesDatabase
 Dim prfview As NotesView
 Dim prfdoc As NotesDocument
 Dim maildb As NotesDatabase
 Dim maildbvw As NotesView
 Dim maildbdoc As NotesDocument
 Dim domvw As NotesView
 Dim domdoc As NotesDocument
 Dim fromitem As NotesItem
 Dim fromval As String
 Dim toval As String
 Dim infodoc As NotesDocument
 Dim polarisdomain As Boolean
 Dim otherdomainto As Boolean
 Dim otherdomaincc As Boolean
 Dim torole As String
 Dim copyval As String
 Dim copyrole As String
 Dim n As Integer
 Dim m As Integer
 Dim a As Integer
 Dim b As Integer
 Dim temptorole As Boolean
 Dim tempcopyrole As Boolean
 Dim temptorole_rec As Boolean
 Dim tempcopyrole_rec As Boolean
 Dim Recipientsrole As String
 Dim temp As String

 Dim FromValSender As String
 
 temptorole=False
 tempcopyrole=False
 temptorole_rec=False
 tempcopyrole_rec=False


 Set curdb=session.Currentdatabase

 Set domvw=curdb.Getview("DomainNamsVw")
 Set domdoc=domvw.Getfirstdocument()

 Set prfview=curdb.Getview("Profile")
 Set prfdoc=prfview.Getfirstdocument()

 If prfdoc Is Nothing Then
  Exit Sub
 End If
 While Not prfdoc Is Nothing
  Set maildb=session.Getdatabase(prfdoc.sername(0),prfdoc.filename(0))
  Set maildbvw=maildb.Getview("($All)")
  Set maildbdoc=maildbvw.Getfirstdocument()
  If maildbdoc Is Nothing Then
   Exit Sub
  End If
  a=0
  b=0
  While Not maildbdoc Is Nothing
   FromValSender = False
   polarisdomain = False
   otherdomainto= False
   otherdomaincc= False
   temptorole=False
   tempcopyrole=False
   temptorole_rec=False
   tempcopyrole_rec=False
  
   copyrole=""
   torole=""
   temp=""
   'Forall obj In domdoc.domains    '//Mail from other domain ex: gmail to polarisFt
    fromval = CStr(maildbdoc.from(0))             '// only From is validated for Gmail
    toval=maildbdoc.SendTo(0)
    copyval=maildbdoc.CopyTo(0)
   ForAll obj In domdoc.domains
     If InStr(Trim(UCase(CStr(fromval))),Trim(UCase(CStr(obj)))) > 0 Then  'Condition for Mail from other Domain to polaris domain receiver
       polarisdomain = True   
     End If
   End ForAll 
   ForAll obj In domdoc.domains             '//Mail from polaris domain to others  ex; PolarisFt to Gmail
     If InStr(Trim(UCase(CStr(fromval))),Trim(UCase(CStr(obj)))) > 0 Then
      FromValSender = true
      'To Condition
      If UBound(maildbdoc.SendTo) > 0 Then
        ForAll z In maildbdoc.SendTo      
       ForAll k In domdoc.domains
        If (Trim(z) = "") Then
         Exit forall
        End If
        If  (InStr(z,"@") = 0 Or (InStr(Trim(UCase(z)),Trim(UCase(k))) > 0)) Then  '// for group name and valid polaris domain name checking
          otherdomainto = True
          Exit ForAll
         End If
       End ForAll
       If otherdomainto = False Then   
        Exit forall
       End If  
        End ForAll
         Else
       otherdomainto = true
         End If
          
      'CC Condition
      If UBound(maildbdoc.CopyTo) > 0 Then
        ForAll j In maildbdoc.CopyTo
       ForAll g In domdoc.domains
        If (Trim(j)= "") Then
         Exit forall
        End If
        If  (InStr(j,"@") = 0 Or (InStr(Trim(UCase(j)),Trim(UCase(g))) > 0)) Then
         otherdomaincc = True
            Exit ForAll
        End If
       End ForAll
      
       If otherdomaincc = False Then    '// for group name checking
        Exit ForAll
       End If
            
      End ForAll
       Else
      otherdomaincc = true
       End If
    Exit forall
   End If
   End ForAll
 
   'Mail from other Domain to polaris domain
  If (polarisdomain = False) Then             '//create receiver doc
    n=1
    ForAll x In maildbdoc.SendTo
     If Trim(x)="" Then
      Exit ForAll
     End If
    
     ForAll p In domdoc.domains
      If (InStr(Trim(UCase(x)),Trim(UCase(p))) > 0) Then
       temptorole_rec = True
       Exit ForAll
      End If
     End ForAll
     If (temptorole_rec = True) Then
     
      Set infodoc = curdb.CreateDocument
      infodoc.form="Information_Receiver"
      infodoc.txt_sender = maildbdoc.from(0)
      infodoc.txt_date = maildbdoc.PostedDate(0)
      infodoc.mid_receiver=maildbdoc.Universalid
      'infodoc.txt_to = x
      infodoc.receivernam="Receiver"
      infodoc.txt_receiver = x
      infodoc.txt_dbname=maildb.Filename
      infodoc.count_receiver="1"
      Call infodoc.Save( True, True )
     
     End If
     n=0
     temptorole_rec=False
     tempcopyrole_rec=False
    End ForAll
    m=1
    ForAll y In maildbdoc.CopyTo
     If Trim(y)="" Then
      Exit ForAll
     End If
     ForAll q In domdoc.domains
      If (InStr(Trim(UCase(y)),Trim(UCase(q))) > 0) Then
       tempcopyrole_rec = True
       Exit ForAll
      End If
     End ForAll
     If (tempcopyrole_rec = True) Then
      Set infodoc = curdb.CreateDocument
      infodoc.form="Information_Receiver"
      infodoc.txt_sender = maildbdoc.from(0)
      infodoc.txt_date = maildbdoc.PostedDate(0)
      infodoc.mid_receiver=maildbdoc.Universalid
      'infodoc.txt_cc = y
      infodoc.txt_receiver = y
      infodoc.receivernam="Receiver"
      infodoc.txt_dbname=maildb.Filename
      infodoc.count_receiver="1"
      Call infodoc.Save( True, True )
     End If
     m=0
     temptorole_rec=False
     tempcopyrole_rec=False
    End ForAll
  End If
 
   'If the polaris domain to otherdomain
   If  FromValSender = True And (otherdomainto = False Or otherdomaincc = False) Then   '//create sender doc
     ForAll s In maildbdoc.SendTo
      ForAll d In domdoc.domains
       If (InStr(Trim(UCase(s)),Trim(UCase(d))) > 0) Then
        temptorole = True
        Exit ForAll
       End If
      End ForAll
      If (Trim(s)="") Then
       Exit ForAll
      End If
      a=1
      If (temptorole = False) Then
       Set infodoc = curdb.CreateDocument
       infodoc.form="Information_Sender"
       infodoc.txt_sender = maildbdoc.from(0)
       infodoc.txt_date = maildbdoc.PostedDate(0)
       infodoc.mid_sender=maildbdoc.Universalid
       'torole=torole+s+","
       infodoc.txt_receiver = s
       infodoc.sendernam = "Sender"
       infodoc.txt_dbname=maildb.Filename
       infodoc.count_sender="1"
       Call infodoc.Save( True, True ) 
      End If
      a=0
     
     End ForAll
   
    b=1
    copyrole=""
     ForAll h In maildbdoc.CopyTo
     
      ForAll e In domdoc.domains
       If (InStr(Trim(UCase(h)),Trim(UCase(e))) > 0) Then
        tempcopyrole = True
        Exit ForAll
       End If
      End ForAll
     
      If (Trim(h) = "") Then
       Exit ForAll
      End If
      b=1
      If (tempcopyrole = False) Then
       Set infodoc = curdb.CreateDocument
       infodoc.form="Information_Sender"
       infodoc.txt_sender = maildbdoc.from(0)
       infodoc.txt_date = maildbdoc.PostedDate(0)
       infodoc.sendernam = "Sender"
       infodoc.mid_sender=maildbdoc.Universalid
       'copyrole=copyrole+h+","
       infodoc.txt_receiver = h
       infodoc.count_sender="1"
       infodoc.txt_dbname=maildb.Filename
       Call infodoc.Save( True, True )
      End If
     
      %REM
      
      If (Trim(h)="") Then
       Exit ForAll
      End If
      %END REM
      b=0
       End ForAll
   End If
   polarisdomain = False
   otherdomainto=False
   otherdomaincc=False
   temptorole=False
   tempcopyrole=False
   temptorole_rec=False
   tempcopyrole_rec=False
   Set maildbdoc=maildbvw.Getnextdocument(maildbdoc)
  Wend
  Set prfdoc=prfview.Getnextdocument(prfdoc)
 Wend
 MsgBox "Done"
End Sub

Extract the Mails from Mail DB (i.e who are sending to ther domains

Sub Initialize
 Dim session As New NotesSession
 Dim curdb As NotesDatabase
 Dim prfview As NotesView
 Dim prfdoc As NotesDocument
 Dim maildb As NotesDatabase
 Dim maildbvw As NotesView
 Dim maildbdoc As NotesDocument
 Dim domvw As NotesView
 Dim domdoc As NotesDocument
 Dim fromitem As NotesItem
 Dim fromval As String
 Dim toval As String
 Dim infodoc As NotesDocument
 Dim polarisdomain As Boolean
 Dim otherdomainto As Boolean
 Dim otherdomaincc As Boolean
 Dim torole As String
 Dim copyval As String
 Dim copyrole As String
 Dim n As Integer
 Dim m As Integer
 Dim a As Integer
 Dim b As Integer
 Dim temptorole As Boolean
 Dim tempcopyrole As Boolean
 Dim temptorole_rec As Boolean
 Dim tempcopyrole_rec As Boolean
 Dim Recipientsrole As String
 Dim temp As String

 Dim FromValSender As String
 
 temptorole=False
 tempcopyrole=False
 temptorole_rec=False
 tempcopyrole_rec=False


 Set curdb=session.Currentdatabase

 Set domvw=curdb.Getview("DomainNamsVw")
 Set domdoc=domvw.Getfirstdocument()

 Set prfview=curdb.Getview("Profile")
 Set prfdoc=prfview.Getfirstdocument()

 If prfdoc Is Nothing Then
  Exit Sub
 End If
 While Not prfdoc Is Nothing
  Set maildb=session.Getdatabase(prfdoc.sername(0),prfdoc.filename(0))
  Set maildbvw=maildb.Getview("($All)")
  Set maildbdoc=maildbvw.Getfirstdocument()
  If maildbdoc Is Nothing Then
   Exit Sub
  End If
  a=0
  b=0
  While Not maildbdoc Is Nothing
   FromValSender = False
   polarisdomain = False
   otherdomainto= False
   otherdomaincc= False
   temptorole=False
   tempcopyrole=False
   temptorole_rec=False
   tempcopyrole_rec=False
  
   copyrole=""
   torole=""
   temp=""
   'Forall obj In domdoc.domains    '//Mail from other domain ex: gmail to polarisFt
    fromval = CStr(maildbdoc.from(0))             '// only From is validated for Gmail
    toval=maildbdoc.SendTo(0)
    copyval=maildbdoc.CopyTo(0)
   ForAll obj In domdoc.domains
     If InStr(Trim(UCase(CStr(fromval))),Trim(UCase(CStr(obj)))) > 0 Then  'Condition for Mail from other Domain to polaris domain receiver
       polarisdomain = True   
     End If
   End ForAll 
   ForAll obj In domdoc.domains             '//Mail from polaris domain to others  ex; PolarisFt to Gmail
     If InStr(Trim(UCase(CStr(fromval))),Trim(UCase(CStr(obj)))) > 0 Then
      FromValSender = true
      'To Condition
      If UBound(maildbdoc.SendTo) > 0 Then
        ForAll z In maildbdoc.SendTo      
       ForAll k In domdoc.domains
        If (Trim(z) = "") Then
         Exit forall
        End If
        If  (InStr(z,"@") = 0 Or (InStr(Trim(UCase(z)),Trim(UCase(k))) > 0)) Then  '// for group name and valid polaris domain name checking
          otherdomainto = True
          Exit ForAll
         End If
       End ForAll
       If otherdomainto = False Then   
        Exit forall
       End If  
        End ForAll
         Else
       otherdomainto = true
         End If
          
      'CC Condition
      If UBound(maildbdoc.CopyTo) > 0 Then
        ForAll j In maildbdoc.CopyTo
       ForAll g In domdoc.domains
        If (Trim(j)= "") Then
         Exit forall
        End If
        If  (InStr(j,"@") = 0 Or (InStr(Trim(UCase(j)),Trim(UCase(g))) > 0)) Then
         otherdomaincc = True
            Exit ForAll
        End If
       End ForAll
      
       If otherdomaincc = False Then    '// for group name checking
        Exit ForAll
       End If
            
      End ForAll
       Else
      otherdomaincc = true
       End If
    Exit forall
   End If
   End ForAll
 
   'Mail from other Domain to polaris domain
  If (polarisdomain = False) Then             '//create receiver doc
    n=1
    ForAll x In maildbdoc.SendTo
     If Trim(x)="" Then
      Exit ForAll
     End If
    
     ForAll p In domdoc.domains
      If (InStr(Trim(UCase(x)),Trim(UCase(p))) > 0) Then
       temptorole_rec = True
       Exit ForAll
      End If
     End ForAll
     If (temptorole_rec = True) Then
     
      Set infodoc = curdb.CreateDocument
      infodoc.form="Information_Receiver"
      infodoc.txt_sender = maildbdoc.from(0)
      infodoc.txt_date = maildbdoc.PostedDate(0)
      infodoc.mid_receiver=maildbdoc.Universalid
      'infodoc.txt_to = x
      infodoc.receivernam="Receiver"
      infodoc.txt_receiver = x
      infodoc.txt_dbname=maildb.Filename
      infodoc.count_receiver="1"
      Call infodoc.Save( True, True )
     
     End If
     n=0
     temptorole_rec=False
     tempcopyrole_rec=False
    End ForAll
    m=1
    ForAll y In maildbdoc.CopyTo
     If Trim(y)="" Then
      Exit ForAll
     End If
     ForAll q In domdoc.domains
      If (InStr(Trim(UCase(y)),Trim(UCase(q))) > 0) Then
       tempcopyrole_rec = True
       Exit ForAll
      End If
     End ForAll
     If (tempcopyrole_rec = True) Then
      Set infodoc = curdb.CreateDocument
      infodoc.form="Information_Receiver"
      infodoc.txt_sender = maildbdoc.from(0)
      infodoc.txt_date = maildbdoc.PostedDate(0)
      infodoc.mid_receiver=maildbdoc.Universalid
      'infodoc.txt_cc = y
      infodoc.txt_receiver = y
      infodoc.receivernam="Receiver"
      infodoc.txt_dbname=maildb.Filename
      infodoc.count_receiver="1"
      Call infodoc.Save( True, True )
     End If
     m=0
     temptorole_rec=False
     tempcopyrole_rec=False
    End ForAll
  End If
 
   'If the polaris domain to otherdomain
   If  FromValSender = True And (otherdomainto = False Or otherdomaincc = False) Then   '//create sender doc
     ForAll s In maildbdoc.SendTo
      ForAll d In domdoc.domains
       If (InStr(Trim(UCase(s)),Trim(UCase(d))) > 0) Then
        temptorole = True
        Exit ForAll
       End If
      End ForAll
      If (Trim(s)="") Then
       Exit ForAll
      End If
      a=1
      If (temptorole = False) Then
       Set infodoc = curdb.CreateDocument
       infodoc.form="Information_Sender"
       infodoc.txt_sender = maildbdoc.from(0)
       infodoc.txt_date = maildbdoc.PostedDate(0)
       infodoc.mid_sender=maildbdoc.Universalid
       'torole=torole+s+","
       infodoc.txt_receiver = s
       infodoc.sendernam = "Sender"
       infodoc.txt_dbname=maildb.Filename
       infodoc.count_sender="1"
       Call infodoc.Save( True, True ) 
      End If
      a=0
     
     End ForAll
   
    b=1
    copyrole=""
     ForAll h In maildbdoc.CopyTo
     
      ForAll e In domdoc.domains
       If (InStr(Trim(UCase(h)),Trim(UCase(e))) > 0) Then
        tempcopyrole = True
        Exit ForAll
       End If
      End ForAll
     
      If (Trim(h) = "") Then
       Exit ForAll
      End If
      b=1
      If (tempcopyrole = False) Then
       Set infodoc = curdb.CreateDocument
       infodoc.form="Information_Sender"
       infodoc.txt_sender = maildbdoc.from(0)
       infodoc.txt_date = maildbdoc.PostedDate(0)
       infodoc.sendernam = "Sender"
       infodoc.mid_sender=maildbdoc.Universalid
       'copyrole=copyrole+h+","
       infodoc.txt_receiver = h
       infodoc.count_sender="1"
       infodoc.txt_dbname=maildb.Filename
       Call infodoc.Save( True, True )
      End If
     
      %REM
      
      If (Trim(h)="") Then
       Exit ForAll
      End If
      %END REM
      b=0
       End ForAll
   End If
   polarisdomain = False
   otherdomainto=False
   otherdomaincc=False
   temptorole=False
   tempcopyrole=False
   temptorole_rec=False
   tempcopyrole_rec=False
   Set maildbdoc=maildbvw.Getnextdocument(maildbdoc)
  Wend
  Set prfdoc=prfview.Getnextdocument(prfdoc)
 Wend
 MsgBox "Done"
End Sub

Extract the Mails from Mail DB who are sending to ther domains

Sub Initialize
 Dim session As New NotesSession
 Dim curdb As NotesDatabase
 Dim prfview As NotesView
 Dim prfdoc As NotesDocument
 Dim maildb As NotesDatabase
 Dim maildbvw As NotesView
 Dim maildbdoc As NotesDocument
 Dim domvw As NotesView
 Dim domdoc As NotesDocument
 Dim fromitem As NotesItem
 Dim fromval As String
 Dim toval As String
 Dim infodoc As NotesDocument
 Dim polarisdomain As Boolean
 Dim otherdomainto As Boolean
 Dim otherdomaincc As Boolean
 Dim torole As String
 Dim copyval As String
 Dim copyrole As String
 Dim n As Integer
 Dim m As Integer
 Dim a As Integer
 Dim b As Integer
 Dim temptorole As Boolean
 Dim tempcopyrole As Boolean
 Dim temptorole_rec As Boolean
 Dim tempcopyrole_rec As Boolean
 Dim Recipientsrole As String
 Dim temp As String

 Dim FromValSender As String
 
 temptorole=False
 tempcopyrole=False
 temptorole_rec=False
 tempcopyrole_rec=False


 Set curdb=session.Currentdatabase

 Set domvw=curdb.Getview("DomainNamsVw")
 Set domdoc=domvw.Getfirstdocument()

 Set prfview=curdb.Getview("Profile")
 Set prfdoc=prfview.Getfirstdocument()

 If prfdoc Is Nothing Then
  Exit Sub
 End If
 While Not prfdoc Is Nothing
  Set maildb=session.Getdatabase(prfdoc.sername(0),prfdoc.filename(0))
  Set maildbvw=maildb.Getview("($All)")
  Set maildbdoc=maildbvw.Getfirstdocument()
  If maildbdoc Is Nothing Then
   Exit Sub
  End If
  a=0
  b=0
  While Not maildbdoc Is Nothing
   FromValSender = False
   polarisdomain = False
   otherdomainto= False
   otherdomaincc= False
   temptorole=False
   tempcopyrole=False
   temptorole_rec=False
   tempcopyrole_rec=False
  
   copyrole=""
   torole=""
   temp=""
   'Forall obj In domdoc.domains    '//Mail from other domain ex: gmail to polarisFt
    fromval = CStr(maildbdoc.from(0))             '// only From is validated for Gmail
    toval=maildbdoc.SendTo(0)
    copyval=maildbdoc.CopyTo(0)
   ForAll obj In domdoc.domains
     If InStr(Trim(UCase(CStr(fromval))),Trim(UCase(CStr(obj)))) > 0 Then  'Condition for Mail from other Domain to polaris domain receiver
       polarisdomain = True   
     End If
   End ForAll 
   ForAll obj In domdoc.domains             '//Mail from polaris domain to others  ex; PolarisFt to Gmail
     If InStr(Trim(UCase(CStr(fromval))),Trim(UCase(CStr(obj)))) > 0 Then
      FromValSender = true
      'To Condition
      If UBound(maildbdoc.SendTo) > 0 Then
        ForAll z In maildbdoc.SendTo      
       ForAll k In domdoc.domains
        If (Trim(z) = "") Then
         Exit forall
        End If
        If  (InStr(z,"@") = 0 Or (InStr(Trim(UCase(z)),Trim(UCase(k))) > 0)) Then  '// for group name and valid polaris domain name checking
          otherdomainto = True
          Exit ForAll
         End If
       End ForAll
       If otherdomainto = False Then   
        Exit forall
       End If  
        End ForAll
         Else
       otherdomainto = true
         End If
          
      'CC Condition
      If UBound(maildbdoc.CopyTo) > 0 Then
        ForAll j In maildbdoc.CopyTo
       ForAll g In domdoc.domains
        If (Trim(j)= "") Then
         Exit forall
        End If
        If  (InStr(j,"@") = 0 Or (InStr(Trim(UCase(j)),Trim(UCase(g))) > 0)) Then
         otherdomaincc = True
            Exit ForAll
        End If
       End ForAll
      
       If otherdomaincc = False Then    '// for group name checking
        Exit ForAll
       End If
            
      End ForAll
       Else
      otherdomaincc = true
       End If
    Exit forall
   End If
   End ForAll
 
   'Mail from other Domain to polaris domain
  If (polarisdomain = False) Then             '//create receiver doc
    n=1
    ForAll x In maildbdoc.SendTo
     If Trim(x)="" Then
      Exit ForAll
     End If
    
     ForAll p In domdoc.domains
      If (InStr(Trim(UCase(x)),Trim(UCase(p))) > 0) Then
       temptorole_rec = True
       Exit ForAll
      End If
     End ForAll
     If (temptorole_rec = True) Then
     
      Set infodoc = curdb.CreateDocument
      infodoc.form="Information_Receiver"
      infodoc.txt_sender = maildbdoc.from(0)
      infodoc.txt_date = maildbdoc.PostedDate(0)
      infodoc.mid_receiver=maildbdoc.Universalid
      'infodoc.txt_to = x
      infodoc.receivernam="Receiver"
      infodoc.txt_receiver = x
      infodoc.txt_dbname=maildb.Filename
      infodoc.count_receiver="1"
      Call infodoc.Save( True, True )
     
     End If
     n=0
     temptorole_rec=False
     tempcopyrole_rec=False
    End ForAll
    m=1
    ForAll y In maildbdoc.CopyTo
     If Trim(y)="" Then
      Exit ForAll
     End If
     ForAll q In domdoc.domains
      If (InStr(Trim(UCase(y)),Trim(UCase(q))) > 0) Then
       tempcopyrole_rec = True
       Exit ForAll
      End If
     End ForAll
     If (tempcopyrole_rec = True) Then
      Set infodoc = curdb.CreateDocument
      infodoc.form="Information_Receiver"
      infodoc.txt_sender = maildbdoc.from(0)
      infodoc.txt_date = maildbdoc.PostedDate(0)
      infodoc.mid_receiver=maildbdoc.Universalid
      'infodoc.txt_cc = y
      infodoc.txt_receiver = y
      infodoc.receivernam="Receiver"
      infodoc.txt_dbname=maildb.Filename
      infodoc.count_receiver="1"
      Call infodoc.Save( True, True )
     End If
     m=0
     temptorole_rec=False
     tempcopyrole_rec=False
    End ForAll
  End If
 
   'If the polaris domain to otherdomain
   If  FromValSender = True And (otherdomainto = False Or otherdomaincc = False) Then   '//create sender doc
     ForAll s In maildbdoc.SendTo
      ForAll d In domdoc.domains
       If (InStr(Trim(UCase(s)),Trim(UCase(d))) > 0) Then
        temptorole = True
        Exit ForAll
       End If
      End ForAll
      If (Trim(s)="") Then
       Exit ForAll
      End If
      a=1
      If (temptorole = False) Then
       Set infodoc = curdb.CreateDocument
       infodoc.form="Information_Sender"
       infodoc.txt_sender = maildbdoc.from(0)
       infodoc.txt_date = maildbdoc.PostedDate(0)
       infodoc.mid_sender=maildbdoc.Universalid
       'torole=torole+s+","
       infodoc.txt_receiver = s
       infodoc.sendernam = "Sender"
       infodoc.txt_dbname=maildb.Filename
       infodoc.count_sender="1"
       Call infodoc.Save( True, True ) 
      End If
      a=0
     
     End ForAll
   
    b=1
    copyrole=""
     ForAll h In maildbdoc.CopyTo
     
      ForAll e In domdoc.domains
       If (InStr(Trim(UCase(h)),Trim(UCase(e))) > 0) Then
        tempcopyrole = True
        Exit ForAll
       End If
      End ForAll
     
      If (Trim(h) = "") Then
       Exit ForAll
      End If
      b=1
      If (tempcopyrole = False) Then
       Set infodoc = curdb.CreateDocument
       infodoc.form="Information_Sender"
       infodoc.txt_sender = maildbdoc.from(0)
       infodoc.txt_date = maildbdoc.PostedDate(0)
       infodoc.sendernam = "Sender"
       infodoc.mid_sender=maildbdoc.Universalid
       'copyrole=copyrole+h+","
       infodoc.txt_receiver = h
       infodoc.count_sender="1"
       infodoc.txt_dbname=maildb.Filename
       Call infodoc.Save( True, True )
      End If
     
      %REM
      
      If (Trim(h)="") Then
       Exit ForAll
      End If
      %END REM
      b=0
       End ForAll
   End If
   polarisdomain = False
   otherdomainto=False
   otherdomaincc=False
   temptorole=False
   tempcopyrole=False
   temptorole_rec=False
   tempcopyrole_rec=False
   Set maildbdoc=maildbvw.Getnextdocument(maildbdoc)
  Wend
  Set prfdoc=prfview.Getnextdocument(prfdoc)
 Wend
 MsgBox "Done"
End Sub

Extract the Mails who are sending to ther domains

Sub Initialize
 Dim session As New NotesSession
 Dim curdb As NotesDatabase
 Dim prfview As NotesView
 Dim prfdoc As NotesDocument
 Dim maildb As NotesDatabase
 Dim maildbvw As NotesView
 Dim maildbdoc As NotesDocument
 Dim domvw As NotesView
 Dim domdoc As NotesDocument
 Dim fromitem As NotesItem
 Dim fromval As String
 Dim toval As String
 Dim infodoc As NotesDocument
 Dim polarisdomain As Boolean
 Dim otherdomainto As Boolean
 Dim otherdomaincc As Boolean
 Dim torole As String
 Dim copyval As String
 Dim copyrole As String
 Dim n As Integer
 Dim m As Integer
 Dim a As Integer
 Dim b As Integer
 Dim temptorole As Boolean
 Dim tempcopyrole As Boolean
 Dim temptorole_rec As Boolean
 Dim tempcopyrole_rec As Boolean
 Dim Recipientsrole As String
 Dim temp As String

 Dim FromValSender As String
 
 temptorole=False
 tempcopyrole=False
 temptorole_rec=False
 tempcopyrole_rec=False


 Set curdb=session.Currentdatabase

 Set domvw=curdb.Getview("DomainNamsVw")
 Set domdoc=domvw.Getfirstdocument()

 Set prfview=curdb.Getview("Profile")
 Set prfdoc=prfview.Getfirstdocument()

 If prfdoc Is Nothing Then
  Exit Sub
 End If
 While Not prfdoc Is Nothing
  Set maildb=session.Getdatabase(prfdoc.sername(0),prfdoc.filename(0))
  Set maildbvw=maildb.Getview("($All)")
  Set maildbdoc=maildbvw.Getfirstdocument()
  If maildbdoc Is Nothing Then
   Exit Sub
  End If
  a=0
  b=0
  While Not maildbdoc Is Nothing
   FromValSender = False
   polarisdomain = False
   otherdomainto= False
   otherdomaincc= False
   temptorole=False
   tempcopyrole=False
   temptorole_rec=False
   tempcopyrole_rec=False
  
   copyrole=""
   torole=""
   temp=""
   'Forall obj In domdoc.domains    '//Mail from other domain ex: gmail to polarisFt
    fromval = CStr(maildbdoc.from(0))             '// only From is validated for Gmail
    toval=maildbdoc.SendTo(0)
    copyval=maildbdoc.CopyTo(0)
   ForAll obj In domdoc.domains
     If InStr(Trim(UCase(CStr(fromval))),Trim(UCase(CStr(obj)))) > 0 Then  'Condition for Mail from other Domain to polaris domain receiver
       polarisdomain = True   
     End If
   End ForAll 
   ForAll obj In domdoc.domains             '//Mail from polaris domain to others  ex; PolarisFt to Gmail
     If InStr(Trim(UCase(CStr(fromval))),Trim(UCase(CStr(obj)))) > 0 Then
      FromValSender = true
      'To Condition
      If UBound(maildbdoc.SendTo) > 0 Then
        ForAll z In maildbdoc.SendTo      
       ForAll k In domdoc.domains
        If (Trim(z) = "") Then
         Exit forall
        End If
        If  (InStr(z,"@") = 0 Or (InStr(Trim(UCase(z)),Trim(UCase(k))) > 0)) Then  '// for group name and valid polaris domain name checking
          otherdomainto = True
          Exit ForAll
         End If
       End ForAll
       If otherdomainto = False Then   
        Exit forall
       End If  
        End ForAll
         Else
       otherdomainto = true
         End If
          
      'CC Condition
      If UBound(maildbdoc.CopyTo) > 0 Then
        ForAll j In maildbdoc.CopyTo
       ForAll g In domdoc.domains
        If (Trim(j)= "") Then
         Exit forall
        End If
        If  (InStr(j,"@") = 0 Or (InStr(Trim(UCase(j)),Trim(UCase(g))) > 0)) Then
         otherdomaincc = True
            Exit ForAll
        End If
       End ForAll
      
       If otherdomaincc = False Then    '// for group name checking
        Exit ForAll
       End If
            
      End ForAll
       Else
      otherdomaincc = true
       End If
    Exit forall
   End If
   End ForAll
 
   'Mail from other Domain to polaris domain
  If (polarisdomain = False) Then             '//create receiver doc
    n=1
    ForAll x In maildbdoc.SendTo
     If Trim(x)="" Then
      Exit ForAll
     End If
    
     ForAll p In domdoc.domains
      If (InStr(Trim(UCase(x)),Trim(UCase(p))) > 0) Then
       temptorole_rec = True
       Exit ForAll
      End If
     End ForAll
     If (temptorole_rec = True) Then
     
      Set infodoc = curdb.CreateDocument
      infodoc.form="Information_Receiver"
      infodoc.txt_sender = maildbdoc.from(0)
      infodoc.txt_date = maildbdoc.PostedDate(0)
      infodoc.mid_receiver=maildbdoc.Universalid
      'infodoc.txt_to = x
      infodoc.receivernam="Receiver"
      infodoc.txt_receiver = x
      infodoc.txt_dbname=maildb.Filename
      infodoc.count_receiver="1"
      Call infodoc.Save( True, True )
     
     End If
     n=0
     temptorole_rec=False
     tempcopyrole_rec=False
    End ForAll
    m=1
    ForAll y In maildbdoc.CopyTo
     If Trim(y)="" Then
      Exit ForAll
     End If
     ForAll q In domdoc.domains
      If (InStr(Trim(UCase(y)),Trim(UCase(q))) > 0) Then
       tempcopyrole_rec = True
       Exit ForAll
      End If
     End ForAll
     If (tempcopyrole_rec = True) Then
      Set infodoc = curdb.CreateDocument
      infodoc.form="Information_Receiver"
      infodoc.txt_sender = maildbdoc.from(0)
      infodoc.txt_date = maildbdoc.PostedDate(0)
      infodoc.mid_receiver=maildbdoc.Universalid
      'infodoc.txt_cc = y
      infodoc.txt_receiver = y
      infodoc.receivernam="Receiver"
      infodoc.txt_dbname=maildb.Filename
      infodoc.count_receiver="1"
      Call infodoc.Save( True, True )
     End If
     m=0
     temptorole_rec=False
     tempcopyrole_rec=False
    End ForAll
  End If
 
   'If the polaris domain to otherdomain
   If  FromValSender = True And (otherdomainto = False Or otherdomaincc = False) Then   '//create sender doc
     ForAll s In maildbdoc.SendTo
      ForAll d In domdoc.domains
       If (InStr(Trim(UCase(s)),Trim(UCase(d))) > 0) Then
        temptorole = True
        Exit ForAll
       End If
      End ForAll
      If (Trim(s)="") Then
       Exit ForAll
      End If
      a=1
      If (temptorole = False) Then
       Set infodoc = curdb.CreateDocument
       infodoc.form="Information_Sender"
       infodoc.txt_sender = maildbdoc.from(0)
       infodoc.txt_date = maildbdoc.PostedDate(0)
       infodoc.mid_sender=maildbdoc.Universalid
       'torole=torole+s+","
       infodoc.txt_receiver = s
       infodoc.sendernam = "Sender"
       infodoc.txt_dbname=maildb.Filename
       infodoc.count_sender="1"
       Call infodoc.Save( True, True ) 
      End If
      a=0
     
     End ForAll
   
    b=1
    copyrole=""
     ForAll h In maildbdoc.CopyTo
     
      ForAll e In domdoc.domains
       If (InStr(Trim(UCase(h)),Trim(UCase(e))) > 0) Then
        tempcopyrole = True
        Exit ForAll
       End If
      End ForAll
     
      If (Trim(h) = "") Then
       Exit ForAll
      End If
      b=1
      If (tempcopyrole = False) Then
       Set infodoc = curdb.CreateDocument
       infodoc.form="Information_Sender"
       infodoc.txt_sender = maildbdoc.from(0)
       infodoc.txt_date = maildbdoc.PostedDate(0)
       infodoc.sendernam = "Sender"
       infodoc.mid_sender=maildbdoc.Universalid
       'copyrole=copyrole+h+","
       infodoc.txt_receiver = h
       infodoc.count_sender="1"
       infodoc.txt_dbname=maildb.Filename
       Call infodoc.Save( True, True )
      End If
     
      %REM
      
      If (Trim(h)="") Then
       Exit ForAll
      End If
      %END REM
      b=0
       End ForAll
   End If
   polarisdomain = False
   otherdomainto=False
   otherdomaincc=False
   temptorole=False
   tempcopyrole=False
   temptorole_rec=False
   tempcopyrole_rec=False
   Set maildbdoc=maildbvw.Getnextdocument(maildbdoc)
  Wend
  Set prfdoc=prfview.Getnextdocument(prfdoc)
 Wend
 MsgBox "Done"
End Sub
Sub Initialize
 Dim session As New NotesSession
 Dim curdb As NotesDatabase
 Dim prfview As NotesView
 Dim prfdoc As NotesDocument
 Dim maildb As NotesDatabase
 Dim maildbvw As NotesView
 Dim maildbdoc As NotesDocument
 Dim domvw As NotesView
 Dim domdoc As NotesDocument
 Dim fromitem As NotesItem
 Dim fromval As String
 Dim toval As String
 Dim infodoc As NotesDocument
 Dim polarisdomain As Boolean
 Dim otherdomainto As Boolean
 Dim otherdomaincc As Boolean
 Dim torole As String
 Dim copyval As String
 Dim copyrole As String
 Dim n As Integer
 Dim m As Integer
 Dim a As Integer
 Dim b As Integer
 Dim temptorole As Boolean
 Dim tempcopyrole As Boolean
 Dim temptorole_rec As Boolean
 Dim tempcopyrole_rec As Boolean
 Dim Recipientsrole As String
 Dim temp As String

 Dim FromValSender As String
 
 temptorole=False
 tempcopyrole=False
 temptorole_rec=False
 tempcopyrole_rec=False


 Set curdb=session.Currentdatabase

 Set domvw=curdb.Getview("DomainNamsVw")
 Set domdoc=domvw.Getfirstdocument()

 Set prfview=curdb.Getview("Profile")
 Set prfdoc=prfview.Getfirstdocument()

 If prfdoc Is Nothing Then
  Exit Sub
 End If
 While Not prfdoc Is Nothing
  Set maildb=session.Getdatabase(prfdoc.sername(0),prfdoc.filename(0))
  Set maildbvw=maildb.Getview("($All)")
  Set maildbdoc=maildbvw.Getfirstdocument()
  If maildbdoc Is Nothing Then
   Exit Sub
  End If
  a=0
  b=0
  While Not maildbdoc Is Nothing
   FromValSender = False
   polarisdomain = False
   otherdomainto= False
   otherdomaincc= False
   temptorole=False
   tempcopyrole=False
   temptorole_rec=False
   tempcopyrole_rec=False
  
   copyrole=""
   torole=""
   temp=""
   'Forall obj In domdoc.domains    '//Mail from other domain ex: gmail to polarisFt
    fromval = CStr(maildbdoc.from(0))             '// only From is validated for Gmail
    toval=maildbdoc.SendTo(0)
    copyval=maildbdoc.CopyTo(0)
   ForAll obj In domdoc.domains
     If InStr(Trim(UCase(CStr(fromval))),Trim(UCase(CStr(obj)))) > 0 Then  'Condition for Mail from other Domain to polaris domain receiver
       polarisdomain = True   
     End If
   End ForAll 
   ForAll obj In domdoc.domains             '//Mail from polaris domain to others  ex; PolarisFt to Gmail
     If InStr(Trim(UCase(CStr(fromval))),Trim(UCase(CStr(obj)))) > 0 Then
      FromValSender = true
      'To Condition
      If UBound(maildbdoc.SendTo) > 0 Then
        ForAll z In maildbdoc.SendTo      
       ForAll k In domdoc.domains
        If (Trim(z) = "") Then
         Exit forall
        End If
        If  (InStr(z,"@") = 0 Or (InStr(Trim(UCase(z)),Trim(UCase(k))) > 0)) Then  '// for group name and valid polaris domain name checking
          otherdomainto = True
          Exit ForAll
         End If
       End ForAll
       If otherdomainto = False Then   
        Exit forall
       End If  
        End ForAll
         Else
       otherdomainto = true
         End If
          
      'CC Condition
      If UBound(maildbdoc.CopyTo) > 0 Then
        ForAll j In maildbdoc.CopyTo
       ForAll g In domdoc.domains
        If (Trim(j)= "") Then
         Exit forall
        End If
        If  (InStr(j,"@") = 0 Or (InStr(Trim(UCase(j)),Trim(UCase(g))) > 0)) Then
         otherdomaincc = True
            Exit ForAll
        End If
       End ForAll
      
       If otherdomaincc = False Then    '// for group name checking
        Exit ForAll
       End If
            
      End ForAll
       Else
      otherdomaincc = true
       End If
    Exit forall
   End If
   End ForAll
 
   'Mail from other Domain to polaris domain
  If (polarisdomain = False) Then             '//create receiver doc
    n=1
    ForAll x In maildbdoc.SendTo
     If Trim(x)="" Then
      Exit ForAll
     End If
    
     ForAll p In domdoc.domains
      If (InStr(Trim(UCase(x)),Trim(UCase(p))) > 0) Then
       temptorole_rec = True
       Exit ForAll
      End If
     End ForAll
     If (temptorole_rec = True) Then
     
      Set infodoc = curdb.CreateDocument
      infodoc.form="Information_Receiver"
      infodoc.txt_sender = maildbdoc.from(0)
      infodoc.txt_date = maildbdoc.PostedDate(0)
      infodoc.mid_receiver=maildbdoc.Universalid
      'infodoc.txt_to = x
      infodoc.receivernam="Receiver"
      infodoc.txt_receiver = x
      infodoc.txt_dbname=maildb.Filename
      infodoc.count_receiver="1"
      Call infodoc.Save( True, True )
     
     End If
     n=0
     temptorole_rec=False
     tempcopyrole_rec=False
    End ForAll
    m=1
    ForAll y In maildbdoc.CopyTo
     If Trim(y)="" Then
      Exit ForAll
     End If
     ForAll q In domdoc.domains
      If (InStr(Trim(UCase(y)),Trim(UCase(q))) > 0) Then
       tempcopyrole_rec = True
       Exit ForAll
      End If
     End ForAll
     If (tempcopyrole_rec = True) Then
      Set infodoc = curdb.CreateDocument
      infodoc.form="Information_Receiver"
      infodoc.txt_sender = maildbdoc.from(0)
      infodoc.txt_date = maildbdoc.PostedDate(0)
      infodoc.mid_receiver=maildbdoc.Universalid
      'infodoc.txt_cc = y
      infodoc.txt_receiver = y
      infodoc.receivernam="Receiver"
      infodoc.txt_dbname=maildb.Filename
      infodoc.count_receiver="1"
      Call infodoc.Save( True, True )
     End If
     m=0
     temptorole_rec=False
     tempcopyrole_rec=False
    End ForAll
  End If
 
   'If the polaris domain to otherdomain
   If  FromValSender = True And (otherdomainto = False Or otherdomaincc = False) Then   '//create sender doc
     ForAll s In maildbdoc.SendTo
      ForAll d In domdoc.domains
       If (InStr(Trim(UCase(s)),Trim(UCase(d))) > 0) Then
        temptorole = True
        Exit ForAll
       End If
      End ForAll
      If (Trim(s)="") Then
       Exit ForAll
      End If
      a=1
      If (temptorole = False) Then
       Set infodoc = curdb.CreateDocument
       infodoc.form="Information_Sender"
       infodoc.txt_sender = maildbdoc.from(0)
       infodoc.txt_date = maildbdoc.PostedDate(0)
       infodoc.mid_sender=maildbdoc.Universalid
       'torole=torole+s+","
       infodoc.txt_receiver = s
       infodoc.sendernam = "Sender"
       infodoc.txt_dbname=maildb.Filename
       infodoc.count_sender="1"
       Call infodoc.Save( True, True ) 
      End If
      a=0
     
     End ForAll
   
    b=1
    copyrole=""
     ForAll h In maildbdoc.CopyTo
     
      ForAll e In domdoc.domains
       If (InStr(Trim(UCase(h)),Trim(UCase(e))) > 0) Then
        tempcopyrole = True
        Exit ForAll
       End If
      End ForAll
     
      If (Trim(h) = "") Then
       Exit ForAll
      End If
      b=1
      If (tempcopyrole = False) Then
       Set infodoc = curdb.CreateDocument
       infodoc.form="Information_Sender"
       infodoc.txt_sender = maildbdoc.from(0)
       infodoc.txt_date = maildbdoc.PostedDate(0)
       infodoc.sendernam = "Sender"
       infodoc.mid_sender=maildbdoc.Universalid
       'copyrole=copyrole+h+","
       infodoc.txt_receiver = h
       infodoc.count_sender="1"
       infodoc.txt_dbname=maildb.Filename
       Call infodoc.Save( True, True )
      End If
     
      %REM
      
      If (Trim(h)="") Then
       Exit ForAll
      End If
      %END REM
      b=0
       End ForAll
   End If
   polarisdomain = False
   otherdomainto=False
   otherdomaincc=False
   temptorole=False
   tempcopyrole=False
   temptorole_rec=False
   tempcopyrole_rec=False
   Set maildbdoc=maildbvw.Getnextdocument(maildbdoc)
  Wend
  Set prfdoc=prfview.Getnextdocument(prfdoc)
 Wend
 MsgBox "Done"
End Sub

Monday, May 7, 2012

Hiding tabs in Tabbed Panels - XPages

Hiding tabs in Tabbed Panels - XPages

There was once a requirement where I had to hide and display tabs in XPages as and when the scenario required it.

It took me some time though to find the solution. Though this post may feel simple and straight forward, it discuss about a little trick that you will experience as you follow.

Create an XPage, put two edit boxes named tab1Flag and tab2Flag and give them a default values of 1 and 0 respectively.

In the next line put two buttons.Name them Toggle tab 1 and Toogle tab 2.

Code these buttons such a way that these buttons enable the fields to toogle between values 0 and 1.

Code on Toggle tab 1 button would be some thing like,

var dispVal=getComponent('tab1Flag').getValue();
(dispVal=='1')? getComponent('tab1Flag').setValue('0') : getComponent('tab1Flag').setValue('1')


Replace all 1s by 2s (except for the 3rd line) for the second button

Now drag and drop a tabbeb panel control into the XPage on a new line.

Select the newly created tabbed control, and go to the outline view and select the individual tab properties as illustrated by the following figure.



Select the small diamond near the Visible check box and key in the following code into it.

flagComp=getComponent('tab1Flag').getValue();
(flagComp == '1')? true : false ;


Similarly mark the second tab's visiblity property with the following code,

flagComp=getComponent('tab2Flag').getValue();
(flagComp == '1')? true : false ;


In total the source code of your XPage must be similar to the following,

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">

   
    <xp:br></xp:br>
    <xp:inputText id="tab1Flag" defaultValue="1"></xp:inputText>
    <xp:inputText id="tab2Flag" defaultValue="0"></xp:inputText>
    <xp:br></xp:br>
    <xp:br></xp:br>
    <xp:button value="Toggle tab 1" id="button1">
        <xp:eventHandler event="onclick" submit="true"
            refreshMode="complete">
            <xp:this.action><![CDATA[#{javascript:var dispVal=getComponent('tab1Flag').getValue();
(dispVal=='1')? getComponent('tab1Flag').setValue('0') : getComponent('tab1Flag').setValue('1')}]]></xp:this.action>
        </xp:eventHandler></xp:button>
    <xp:button value="Toggle tab 2" id="button2">
        <xp:eventHandler event="onclick" submit="true"
            refreshMode="complete">
            <xp:this.action><![CDATA[#{javascript:var dispVal=getComponent('tab2Flag').getValue();
(dispVal=='1')? getComponent('tab2Flag').setValue('0') : getComponent('tab2Flag').setValue('1')}]]></xp:this.action>
        </xp:eventHandler></xp:button>
   
    <xp:br></xp:br><xp:tabbedPanel id="tabbedPanel1">
        <xp:tabPanel label="New Tab" id="tabPanel1">tab 1<xp:this.rendered><![CDATA[#{javascript:flagComp=getComponent('tab1Flag').getValue();
(flagComp == '1')? true : false ;}]]></xp:this.rendered></xp:tabPanel>
        <xp:tabPanel label="New Tab2" id="tabPanel2">tab 2<xp:this.rendered><![CDATA[#{javascript:flagComp=getComponent('tab2Flag').getValue();
(flagComp=='1')? true : false ;}]]></xp:this.rendered></xp:tabPanel>
    </xp:tabbedPanel>
    </xp:view>


Now save and preview your XPage. Now you can toggle the tabs visually. That is either hide them or show them.

The trick here is "Atleast one of the tabs must be left visible" . i.e. you can toggle tab2 when tab1 is visible alone and viceversa. If this condition is not satisfied you are going to get your XPage to bombard a run time error.

I dont like this behavior of tabbed panels in XPages, honestly. I think this is an issue with the XPages. I surely know that there are always ways to work around issues and get the desired solutions but, I feel this is not an acceptable behavior of tabbed panels - I mean why should it give you a run time error for a mistake that you are not responsible for... It can simply go hidden instead of giving me a run time error ...

Sunday, May 6, 2012

Simple Dialog Box In XPage

Creating Simple Dialog Box In XPage

The following is a procedure that will help you to create a simple Dojo Dialog Box in XPage

1. Create an XPage
2. Create a Panel and put some text inside it
3. In the All properties tab of the XPage, Mark the parameters, dojoTheme and dojoParseOnLoad as true (refer to the following figure)

4.Move to the source code panel and add the following code snippet

<xp:this.resources>
        <xp:dojoModule name="dijit.Dialog"></xp:dojoModule>
    </xp:this.resources>


5. Now add a button and in the onclick event of the button (client side)
put the following client side javascript

dijit.byId("myDialogContainer").show()

Now preview your XPage on the client or on the browser and click the button.
You will be able to see a nice dojo popup

The source code of the Xpage that I developed for this particular task is as follows,

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" dojoParseOnLoad="true"
    dojoTheme="true">

    <xp:this.resources>
        <xp:dojoModule name="dijit.Dialog"></xp:dojoModule>
    </xp:this.resources>
       
    <xp:button value="Dialog Popup" id="button2">
        <xp:eventHandler event="onclick" submit="false">
            <xp:this.script><![CDATA[dijit.byId("myDialogContainer").show()]]></xp:this.script>
        </xp:eventHandler>
    </xp:button>
   
    <div id="myDialogContainer" dojoType="dijit.Dialog"
        style="display:none">
        <xp:panel>Test Popup</xp:panel>
    </div>
       
</xp:view>