Hi,
We have a requirement of getting incoming mails with PDF attachment only (invoices).
We need to accept the mail
if at least one PDF attachment is there
and the attached PDF is digitally signed.
Else return the mail to the sender with some auto text.
Please guide...
Unfortunately there is no native way to do this in the router itself. There is VB- Code out there that can be easily translated into LotusScript Code to check the digital signature of a PDF file.
You could write an agent "before new mail arrives (better don't, read the response of Lars for the reason)" or "after new mail arrives (preferable)" that runs that code and sends a predefined mail if it does not validate.
For that code to work you need Acrobat reader be installed on the server where the agent runs. Taken from this Stackoverflow post the code would look something like:
Dim gApp As Variant
Dim gPDDoc As Variant
Dim jso As Variant
Dim fname As String
Dim intState as Integer
Dim signField as Variant
Dim blnSignature as Boolean
'- first detach the pdf to some path (code not included)
Set gApp = CreateObject(“AcroExch.App”)
Set gPDDoc = CreateObject(“AcroExch.PDDoc”)
If gPDDoc.Open(“C:\Temp\SomePDF.pdf”) Then '- path where you detached…
Set jso = gPDDoc.GetJSObject
For i = 0 To jso.numFields - 1
fname = jso.getNthFieldName(i)
If jso.getField(fname).type = “signature” then
'- found a signature field, check its validity
Set signField = jso.getField(fname)
intState = signField.SignatureValidate()
If intState = 4 then '- you could accept intState = 3 as it also means signature valid… see documentation
blnSignature = True
Exit For
End If
End If
End If
End If
If not blnSignature then
'- delete document
'- send predefined mail
End If
I did not test this code and it is far from being complete (not to speak from the missing error handler), but it should give you a starting point
Warning: Before New mail arrives code runtime should be SHORT!
For background: https://www.google.com/search?q=julie+kadashevich+"Before+new+mail" specifically, the article titled "Out of the Inbox: Mail processing with the new R5 mail agents"
Note: Any LotusScript writer should read and save all articles by Julie Kadashevich. No matter if they were published a long time ago: Read! They have helped me so many times...
Why SHORT: The Before New Mail agents are exectuted by the Mail Router process, and have several restrictions in place to protect the Router process. See article for details.
Solution: as quickly as possible, determine whether the current mail can be delivered based on simple criteria (checking a cryptographic signature is by definition not simple) or needs further checking.
If it needs further checking, copy the document to a database where the checking will be done, then delete the document being processed. This ensures an unchecked mail is not delivered to the user.
Then a scheduled or After new mail agent (I recommend both, the scheduled agent picking up documents an After New mail agent missed...) uses Acrobat or Java API to check the PDF signature and deliver it if OK. The agent should also post reports of delivery and processing, so SysAdmins and Application Admins can keep tabs on how things are going.
Agree, it would be tricky to add code "Before new mail arrives" as when something happens to the agent it could stack up all incoming emails. A thorough testing should be done before implementing it to your production server.
Also, you can always create an enhancement request using the link below.
https://domino-ideas.hcltechsw.com/
Dear All,
Thank you very much Torsten, LB and JJM.
Definitely, testing is a must.
Since check rule only for fixed emails ( 1 or maximum 2), we can think of writing a script with the start condition ( if the email id is "**" or "***"). This may probably reduce waiting time/cluttering.
We will let you updated.
Regards,
Shishir