Question : Can you help me to script a pre-delivery agent in Domino?

Hello experts,

I am a newbie, trying to write a pre-delivery agent using lotus script. The purpose of the agent is to check the size of the message, if it exceeds certain size (2MB, may be) then remove the attachment (if any) and place a custom message at the end of body.

Your help is highly appreciated.

Answer : Can you help me to script a pre-delivery agent in Domino?

I wrote this directly here, so expect errors :)

We'll clean it up eventually...
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
Sub Initialize
	Dim s As New NotesSession	
	Dim db As NotesDatabase
	Dim c As NotesDocumentCollection
	Dim cur As NotesDocument		
	Dim EmbeddedObjects As Variant
	Dim rtitem As Variant
	Dim AttFileNames List As String
	Dim limit As Long
	
	Const MB_LIMIT& = 2					'Long
	limit = MB_LIMIT * 1024 * 1024	
	
	Set db = s.CurrentDatabase
	Set c = db.UnprocessedDocuments
	
	If c Is Nothing Then Exit Sub
	If c.Count = 0 Then Exit Sub
	
	Set cur = c.GetFirstDocument
	Do Until cur Is Nothing
		
		If cur.Size > limit	 Then		'The size of a document in bytes
			'doc is larger then it should be			
			Set rtitem = cur.GetFirstItem( "Body" )
			
			If Not rtitem Is Nothing Then
				If Not Isnull( rtitem ) Then
					If rtitem.Type = 1 Then	'is it RTF
						
						EmbeddedObjects = rtitem.EmbeddedObjects
						If Not Isempty( EmbeddedObjects ) Then
							
							Forall eo In EmbeddedObjects
								If eo.Type = 1454 Then
									
									'It's attachment, put its name in the list
									AttFileNames( Lcase( eo.Source ) ) = "1"
									
								End If
								
							End Forall
							
							Call rtitem.AppendText( " " )
							Call rtitem.AddNewLine( 3 )
							Call rtitem.AppendText( "The document is larger then the limit of 2MB." )
							Call rtitem.AddNewLine( 2 )
							
							Call rtitem.AppendText( "The following attachments have been removed: " )
							Call rtitem.AddNewLine( 1 )
							
							Forall elem In AttFileNames
								Call rtitem.AddNewLine( 1 )
								Call rtitem.AddTab( 1 )
								Call rtitem.AppendText( "- " )
								Call rtitem.AppendText( Listtag( elem ) )
							End Forall
							
						End If
					End If
				End If
			End If
			
			Call cur.Save( True, False, False )
		End If
		
		Erase AttFileNames	'clean the list
		Set cur = c.GetNextDocument( cur )
	Loop
	
End Sub
Random Solutions  
 
programming4us programming4us