?
Solved

Printing attachments in the protected area of a form.

Posted on 2006-05-18
7
Medium Priority
?
594 Views
Last Modified: 2013-12-18
We receive Faxes from a Right Fax server into our Lotus Notes inbox.  We need an agent that will print the fax attachments without having to individually open each email.  The problem, however, is that the faxes are not attached to the email "Body" but are in a "protected area of the form", thus, the normal method of creating a rich text navigator will not work.  The below code being an example:
               

                Dim rtitem As notesrichtextitem
     
     If doc Is Nothing Then Exit Sub
     If doc.HasItem ("Body") = False Then Exit Sub                                                            
     Set rtitem = doc.GetFirstItem( "Body" )      
     If ( rtitem.Type = RICHTEXT ) = False Then Exit Sub
     If Isempty(rtitem.EmbeddedObjects) Then Exit Sub
     
     Forall o In rtitem.EmbeddedObjects
          If ( o.Type = EMBED_ATTACHMENT ) Then
               Call PrintAttachment (o)
          End If
     End Forall

I do not know how to get at the attachments if they are not in the email body.  When I throw the Lotus Script in debug, I can see the attachments in the document as $FILE items, but they are NotesItems, not rich text items, which leaves me without the embeddedobjects method.  I am at a loss for what to do?  Thank you.
0
Comment
Question by:druss23
  • 5
  • 2
7 Comments
 
LVL 18

Expert Comment

by:marilyng
ID: 16710542
Try the document embedded objects method.. with $file you can get the filename, the document embedded objects will collect all $file, and you can extract from there or launch.

Search on NotesDocument properties, I think (Sorry, not at a Notes Computer today)
0
 
LVL 18

Expert Comment

by:marilyng
ID: 16715141
Yeah,

Sub Initialize
  Dim db As NotesDatabase
  Dim view As NotesView
  Dim doc As NotesDocument
  Set db = New NotesDatabase( "SanFrancisco", "hill.nsf" )
  Set view = db.GetView( "All Documents" )
  Set doc = view.GetLastDocument
  If doc.HasEmbedded Then
    Forall o In doc.EmbeddedObjects
      Messagebox( o.Name )
    End Forall
  Else
    Messagebox "No embedded objects found"
  End If
End Sub

from the Embedded Objects property of NotesDocument
0
 

Author Comment

by:druss23
ID: 16717463
Thank you for the reply.  I receive a type mismatch when running the above code on the Forall line.  I believe this is because the embeddedobjects method in the notesDocument class does not deal with File attachments, everything we receive is a file attachment, it is simply not attached in the body.  From the Notes help about this method in NotesDocument:
Unlike the EmbeddedObjects property in NotesRichTextItem, this property does not include file attachments.  
We are forced to use the embeddedobjects property in NotesRichTextItem, since it is the only one that returns file attachments types.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 18

Expert Comment

by:marilyng
ID: 16721043
No, i don't believe that's the reason, I copied a sample file from the Designer Help, and they typically don't instantiate objects or properties.  Nor do they check for the existance of the properties. :)

So, for instance,
You would need sonething like this:

Dim session as New Notessession
Dim db as Notesdatbase
set db = session.currentdatbase
dim view as Notesview
set view = db.getView("my viewname")
if view is nothing then
 msgbox "Sorry, view not found"
  exit sub
end if
set doc = view.getfirstdocument
while not doc is nothing
   if doc.hasEmbedded then
         forall o in doc.embeddedObjects
             If ( o.Type = EMBED_ATTACHMENT ) Then
                    Call o.ExtractFile( "c:\samples\" & o.Source )
              end if
end forall

set doc = view.getNextDocument(doc)
wend


You need to adjust it.  Are you lotusscript capable?  If not, I will adjust for you, but am not at a Notes computer right now.  

I believe it the instructions for the embedded object that you're seeing is for java, not for the NotesDocument class in LotusScript.  I say this, because I use the doc embedded to detach all attachments from a document when they're not embedded in the RichText field.  So, you can use the rtfield, or the plain doc attachments.  You could probably use the doc.getAttachment( using the $file = filename of the attachment)


Here's another way:  http://www.experts-exchange.com/Applications/Email/Lotus_Notes_Domino/Q_11228338.html?query=embeddedobject&topics=133

when I get home, I will see what I can do to pull a snippet for you.

0
 
LVL 18

Accepted Solution

by:
marilyng earned 2000 total points
ID: 16722655
Ok here is the exact quote:  Unlike the EmbeddedObjects property in NotesRichTextItem, this property does not include file attachments, nor OLE/1 objects created in Notes Release 3.  <<< NOtes Release 3 is the operative phrase here.

Here is a quick and dirty snippet that I had:  (paste into an agent, and run on selected documents)

Sub Initialize
      'Add your correct filepath here..........................
      Const FILEPATH = "C:\Temp\"
      Const DEFAULTEXT = ".txt"
      '................................................................................
      Dim Session As New NotesSession
      Dim db As NotesDatabase
      Set db = session.currentdatabase
      Dim doc As NotesDocument
      Dim coll As NotesDocumentCollection
      Set coll = db.unprocesseddocuments
      
      Dim count As Integer
      Dim NumAttachments As Variant
      Dim attachmentNames As Variant
      Dim strAttachments As String
      Dim formatString As String, filename As String
      Dim object As NotesEmbeddedObject
      Const NumMacro = {@Attachments}
      Const NameMacro = {@AttachmentNames}
      If coll.count <1 Then Exit Sub
      Set doc = coll.getfirstdocument
      While Not doc Is Nothing
            With doc
                  NumAttachments = Evaluate(NumMacro,Doc)
                  AttachmentNames = Evaluate(NameMacro,Doc)                  
                  If doc.HasEmbedded Then
                        If Isarray(attachmentNames) Then
                              Forall a In attachmentNames
                                    If Len(a)<>"" Then
                                          Set object = doc.GetAttachment(a)
                                          If Not object Is Nothing Then
                                                'Making sure I don't overwrite the files, you can do this with a date, too.
                                                count = count +1
                                                FileName = object.Source
                                                If Instr(1, filename, ".", 5)>0 Then
                                        'the attachment has a file extension leave as is.      
                                                      formatString = FILEPATH + Format(count,"00") + "_" + filename
                                                Else
                                                      'I'm adding a file extension...
                                                      formatString = FILEPATH  + Format(count,"00") + "_" + filename + DEFAULTEXT
                                                End If                                                
                                                Call object.ExtractFile(formatString)            
                                                strAttachments = strAttachments + filename + Chr(13)
                                                Print "Detaching " + formatstring + " ..."
                                                'Optional you can delete the attachement and save the file
                                                'However, don't do this if your view collects on attachments else
                                                'you'll lose the pointer
                                                'Call object.Remove
                                                'doc.save True, False, True
                                                '............................................End Optional
                                          End If
                                    End If
                              End Forall
                        End If
                  End If
            End With
            Redim NumAttachments(0)
            Redim AttachmentNames(0)            
            Set doc = coll.GetNextDocument(doc)
      Wend
      
      If Not coll Is Nothing Then Set coll = Nothing
      
      Msgbox {Detached: } + Cstr(count) + { attachments.} + Chr(13) +_
      strAttachments,,"Done"      
End Sub
0
 

Author Comment

by:druss23
ID: 16733501
The operative phrase applies to the second condition (the OLE object).  This is further illustrated in the example section of this same page, which is a little more explicit and not as ambiguously worded.  From the example section:

EmbeddedObjects does not return the Ami Pro document because the object was created in Notes Release 3. It does not return castle.bmp because castle.bmp is a file attachment.

Your code above works (using the GetAttachment method rather than the EmbeddedObject method), and this is what we ultimately will use!  Thank you for your help.
0
 
LVL 18

Expert Comment

by:marilyng
ID: 16738932
Yeah, you have to jump through hoops (some minor ones) to grab the ole object on the document, when I was in a hurry, I did this snippet to grab it fast.  Figured it would be of assistance to you, too. :)

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IBM Notes offer Encryption feature using which the user can secure its NSF emails or entire database easily. In this section we will discuss about the process to Encrypt Incoming and Outgoing Mails in depth.
This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question