Friday, 6 April 2012

Lotus Notes : Restrict Attachment size before Saving Email Document


Below is the code that needs to be added to the QuerySave event of Memo and Reply Forms.
Also, change the Max. Attachment size as required.

Below is the code that needs to be added to the QuerySave event of Memo and Reply Forms.
Also, change the Max. Attachment size as required.

Sub Querysave(Source As Notesuidocument, Continue As Variant)
    If source.InPreviewPane Then Exit Sub
    
    '****************************************************
    '**  Configure Attachment Size here ***********
    Const ATTACH_SIZE = 5 'MB
    '****************************************************
    Dim ws As New NotesUIWorkspace
    Dim uidoc As NotesUIDocument
    Dim doc As NotesDocument
    Dim totalSize As Long
    
    Set uidoc = ws.CurrentDocument
    Set doc = uidoc.document
    
    Call uidoc.GotoField("Body")
    Call uidoc.refresh(True)
    Dim rtitem As Variant
    Dim embedObjs As Variant
    
    Set rtitem = doc.getFirstItem("Body")
    embedObjs = rtitem.embeddedObjects
    totalSize = 0
    Dim oneMB As Long
    oneMB = 1048576
    
    
    If Not Isempty(embedObjs) Then
     For i = 0 To Ubound(embedObjs)
      totalSize = totalSize + embedObjs(i).filesize
     Next
     
     If totalSize > ATTACH_SIZE * oneMB Then
      Msgbox("Your total attachment size is " +Cstr(Round (totalSize /    oneMB,1)) +" mb.  The limit is " + Cstr(ATTACH_SIZE) + " MB.")
      continue = False
      Exit Sub
     End If
    End If
    
    Call source.FieldSetText("useApplet", "True")
    Call cMemoObject.QuerySave(Continue)
End Sub
 

References:
http://www-10.lotus.com/ldd/46dom.nsf/55c38d716d632d9b8525689b005ba1c0/a8ac654c57789e2085256e660074cc05?OpenDocument
http://searchdomino.techtarget.com/tip/Check-attachment-size-before-doc-is-saved