Read attachment without extracting?

Hi, is it possible to read an attachment in a doc without extracting it to a file system? If this is possible, can you please give me a sample of this LotusScript?

Basically, my scenario is that I do a getDocumentByURL to fetch a webpage which would test a user’s membership in a group. Unfortunately, the results are stored in an attachment of that webDoc. I then would like to read the attachment to test the presence of a return code without extracting that attachment. Please advise if this is possible. Thanks.

Subject: Read attachment without extracting?

With Lotusscript, you will always need to detach the file to the file system. You need to use a Java agent and something like getinputstream.

This was found with a simple google search and may help you, as you seem reluctant to write your own Java code:

http://www.hankos.net/A556E9/net.nsf/html/resources/how_to_read_a_text_file_attached_to_a_lotus_notes_document_without_detaching_it.html?OpenDocument

Subject: RE: Read attachment without extracting?

Thank you very much Carl for your reply and patience. Yes, I am a bit more inclined to LotusScript rather than Java.

Thanks for that link of code in Java agent & LS too. I modified my code and it works. So, IT IS possible to read an attachment in LS without extracting it.

Also, I came across other ways using DXL and even NotesDOMparser.

DXL method:

http://www-10.lotus.com/ldd/nd6forum.nsf/55c38d716d632d9b8525689b005ba1c0/447b2cf2af3d3f28852572580068eade?OpenDocument

NotesDOMParser method:

http://www-10.lotus.com/ldd/nd6forum.nsf/55c38d716d632d9b8525689b005ba1c0/8e96e1a798bf8e5a852571830006f0ae?OpenDocument&Highlight=0,read,stream,from,attachment

I am sure others will find these helpful when they want to read an attachment without extracting it.

Subject: Why not share your code?

That way if someone in the future from IBM has the same issue you have had, they can see the solution?

Subject: RE: Why not share your code?

OK Carl, along with the (ReadAttachmentJava) agent code that you had shared by those links, here is my code:

%REM

Agent VerifyUser

Created Feb 5, 2018 by Kingsley E Fernandes-1/India/IBM

Description: Agent to Verify user logged in to ICA is a member of BlueGroups for ICA

%END REM

Option Public

Option Declare

Use “BluePages”

Sub Initialize

On Error GoTo ErrHandle	

Dim s As New NotesSession

Dim db As NotesDatabase

Dim doc As NotesDocument

Dim coll As BPResults

Dim bpd As BluePages

Dim curUser As NotesName

Dim dbProfileView As NotesView

Dim dbProfileDoc As NotesDocument

Dim userEmail As String

Dim BlueGroupsURL As String

Dim url As String

Dim webDoc As NotesDocument

Dim strEncodedUser As String

Dim FileToRead As String

Dim item As NotesItem

Dim paramid As String

Dim agent As NotesAgent



Set doc = s.Documentcontext

Set db = s.Currentdatabase	



'Fetch the BluePages API URL from the Global Configuration Doc

Set dbProfileView = db.Getview("GlobalConfigView")

Set dbProfileDoc = dbProfileView.Getfirstdocument()

Set bpd = New BluePages(dbProfileDoc.EdDirURL(0))



If Not bpd.IsOpen() Or bpd.GetReturnCode() <> 0 Then  

	MessageBox "Error in connecting to BluePages API",, "Error"

	Exit Sub

Else

	MessageBox "Connected to BluePages API"

End If



'Get the Current logged in user from the CGI variable Remote_User		

Set curUser = New NotesName(doc.Remote_User(0))	

MsgBox "In WQO agent: User logged in is " + doc.Remote_User(0) + " Abbv Name = " & curUser.Abbreviated + " Canon = " & curUser.Canonical



strEncodedUser = curUser.Canonical

strEncodedUser = Replace( strEncodedUser, " ", "+")

strEncodedUser = Replace( strEncodedUser, "=", "%3D")

strEncodedUser = Replace( strEncodedUser, "/", "%2F")



MsgBox "Encoded User ID = " & strEncodedUser

'Set coll = bpd.GetPersonsByNotesID("CN%3DKingsley+E+Fernandes-1%2FOU%3DIndia%2FO%3DIBM%25")

Set coll = bpd.GetPersonsByNotesID(strEncodedUser)



If coll.succeeded() Then

	MsgBox "BP message = " & coll.GetErrorMessage() & " code = " & coll.GetReturnCode() & " col rows = " & coll.Rows()                      'If the query completed normally,

	If coll.rows() = 0 Then                    'No records found                               

		Msgbox curUser.Abbreviated & " was not found." & coll.GetColumn("name")  

	ElseIf coll.rows() >= 1  Then              ' coll.rows()>=1   ...and found at least one name,

		Msgbox "Name: " & coll.GetColumn("NAME")(0) & " EMAIL = " & coll.GetColumn("INTERNET")(0)

	End if

End If



userEmail = coll.GetColumn("INTERNET")(0)



MsgBox "To verify " & userEmail & " in ICA BlueGroups"



'Fetch the BlueGroups Validation URL from Global Configuration doc & append the email of user to validate	

BlueGroupsURL = dbProfileDoc.EdBlueGroupsURL(0)

url = BlueGroupsURL & userEmail		



'Fetch the BlueGroups validation webpage which will return the user's membership results in an attached file called groupsxml.wss	

Set webDoc = db.GetDocumentByURL(url,1)

FileToRead = "groupsxml.wss"



Set item = webDoc.AppendItemValue("Filename", FileToRead)

Set item = webDoc.AppendItemValue("UniversalID", webDoc.UniversalID)

Call webDoc.Save(True, False)



'Set the parameter value of the web document which has file to read

paramid = webDoc.Noteid

	

Set agent = db.GetAgent("(ReadAttachmentJava)")

'Start agent and pass note ID of document

'Use agent.RunOnServer(paramid) to run the agent on the server

If agent.RunOnServer(paramid) = 0 Then

	MsgBox "Agent ran - Success"

Else

	MsgBox "Agent did not run - Failure"

End If



'Delete in-memory document. This is necessary because we need to reload 

'the document in order to get the latest data which the Java Agent has 

'written into the parameter document

Delete webDoc 



'Get the result from the parameter document (the data from the file attachment)

Dim theResult As String

Set webDoc = db.GetDocumentByID(paramid)

theResult = webDoc.Result(0)



'Do whatever you need with the data

'Your code goes here



MsgBox "ATTACHED FILE DATA = " & theResult

'When finished delete the temporary parameter document

Call webDoc.RemovePermanently(True)	

'If the return code ZERO is present in that File Data then user is a member of ICA BlueGroup

If InStr( theResult , "<rc>0</rc>") <> 0 Then

	MsgBox "User is a Member of ICADEV BlueGroups"

Else	

	MsgBox "User is NOT a Member of ICADEV BlueGroups"

'If user is not member then redirect page to Authentication Failure screen

	Print "[https://a25zeidb0251g.pok.dst.ibm.com/tools/forms/ica/icaweb.nsf/loginerr]"

End If	



Exit Sub

ErrHandle:

MsgBox "WQO agent error on line = " & Erl & " with msg = " & Error$ 	

End Sub

Subject: RE: Read attachment without extracting?

If the attachment is plain text or a CSV or some such, you ought to be able to get to it using DXL. Bit of a faff, but doable. If it’s something like a Word doc, though, or a binary that needs opening in another program, not so much using LS.

Subject: RE: Read attachment without extracting?

Thanks Stan.

It is possible to read simple files in an Attachment using LS with Java agent, by DXL or even by NotesDOMParser. Shared the links to these 3 methods in my subsequent thread post.

Subject: RE: Read attachment without extracting?

To be clear: NotesDOMParser requires DXL export (as does NotesSAXParser and just plain string manipulation), so the “or even” is kind of baffling.

Subject: RE: Read attachment without extracting?

Thanks for pointing that out, Stan. I’m new to all this DXL stuff :slight_smile:

Subject: Read attachment without extracting?

Try adding this line to you notes.ini file then restart Notes:

AttachmentActionDefault=1

Subject: RE: Read attachment without extracting?

Thanks Michael but I found my solution.

However, what does this parameter in the NOTES.INI file do?

Have not tried it but it does not look like it will allow to read attachments without extracting it. Anyway, I have found the code that would do that so I can process it further.