1 | ' $Id: libDSPAMReporting.lss,v 1.00 2009/12/22 12:25:59 sbajic Exp $
|
---|
2 |
|
---|
3 | %REM
|
---|
4 |
|
---|
5 | ******************************************************************************
|
---|
6 | * libDSPAMReporting - LoutsScript Library for retraining DSPAM mails in *
|
---|
7 | * Lotus Notes/Domino *
|
---|
8 | * *
|
---|
9 | * Copyright 2004, Stevan Bajic <stevan@bajic.ch>, all rights reserved. *
|
---|
10 | * *
|
---|
11 | * You are free to use this code within your own applications, but you are *
|
---|
12 | * expressly forbidden from selling or otherwise distributing this source *
|
---|
13 | * code without prior written consent. This includes both posting free demo *
|
---|
14 | * projects made from this code as well as reproducing the code in text or *
|
---|
15 | * html format. *
|
---|
16 | * *
|
---|
17 | * The DSPAM community project (http://www.sourceforge.net/projects/dspam/) *
|
---|
18 | * is excluded from any licensing limitations. *
|
---|
19 | ******************************************************************************
|
---|
20 |
|
---|
21 | This LotusScript library uses the spam/nonspam alias functionality of DSPAM to
|
---|
22 | retrain messages as SPAM or as NONSPAM.
|
---|
23 |
|
---|
24 | How to make this work?
|
---|
25 | ----------------------
|
---|
26 | Open your mail database (or the mail template) with the Domino Designer and go
|
---|
27 | to "Shared Code", "Script Libraries". Press the action "New LotusScript Library"
|
---|
28 | and in the new created Script Library press in the right pane (there where you
|
---|
29 | would normally type your LotusScript code) the right mouse button and then
|
---|
30 | select "Import...". Browse the file system and select this file here. You will
|
---|
31 | get a dialog box with the title "LotusScript Import Options" asking you if it
|
---|
32 | should replace existing code. Please answer with "Yes to All".
|
---|
33 | Now the code is imported and you should go into the "(Declarations)" and change
|
---|
34 | there your SPAM and HAM alias. The line you should change are:
|
---|
35 | Const SPAM_ALIAS = {spam@mydomain.local}
|
---|
36 | Const NOTSPAM_ALIAS = {notspam@mydomain.local}
|
---|
37 |
|
---|
38 | Just enter the SPAM/NOTSPAM alias you are using in your DSPAM instalaltion.
|
---|
39 |
|
---|
40 | Should you have set the SPAM tag to be anything else then "[SPAM]" the you need
|
---|
41 | to change the SPAM_TAG as well. The line you should change is:
|
---|
42 | Const SPAM_TAG = {[SPAM]}
|
---|
43 |
|
---|
44 | After you have changed those lines you can close the Script Library and save it.
|
---|
45 | The Domino Designer will ask you how to name that new created Script Library.
|
---|
46 | Use something like "libDSPAMReporting" or anything you like. Now you need to go
|
---|
47 | into "Shared Code", "Actions" and press the button "New Shared Action". Domino
|
---|
48 | Designer will create a new Shared Action and show you a property box. In that
|
---|
49 | property box set the Name entry to "SPAM" and the Label to "SPAM" as well. For
|
---|
50 | the Type select "Button" and select "Include action in Action bar" and "Include
|
---|
51 | action in Action menu". For the Icon select the type to be "Notes" and Location
|
---|
52 | to be "Left" and for the icon image anything you like (I use the X wich is the
|
---|
53 | last icon in the first row). Close now the property box and select the type of
|
---|
54 | the Shared Action to be LotusScript. Then select (Options) and type:
|
---|
55 | Use "libDSPAMReporting"
|
---|
56 |
|
---|
57 | Then select the event "Click" and type:
|
---|
58 | Sub Click(Source As Button)
|
---|
59 | Call fnDSPAMReport ( {SPAM} )
|
---|
60 | End Sub
|
---|
61 |
|
---|
62 | Save the Shared Action and press again on "New Shared Action". Domino Designer
|
---|
63 | will create a new Shared Action and show you a property box. In that property
|
---|
64 | box set the Name entry to "NOT SPAM" and the Label to "NOT SPAM" as well. For
|
---|
65 | the Type select "Button" and select "Include action in Action bar" and "Include
|
---|
66 | action in Action menu". For the Icon select the type to be "Notes" and Location
|
---|
67 | to be "Left" and for the icon image anything you like (I use the check mark wich
|
---|
68 | is the second last icon in the first row). Close now the property box and select
|
---|
69 | the type of the Shared Action to be LotusScript. Then select (Options) and type:
|
---|
70 | Use "libDSPAMReporting"
|
---|
71 |
|
---|
72 | Then select the event "Click" and type:
|
---|
73 | Sub Click(Source As Button)
|
---|
74 | Call fnDSPAMReport ( {NOTSPAM} )
|
---|
75 | End Sub
|
---|
76 |
|
---|
77 | Save the Shared Action. Now go to "Folders" and open your INBOX (the folder is
|
---|
78 | probably named "($Inbox)" on your installation). At the right part of the screen
|
---|
79 | you should see a list of actions. Select the first action and then select in the
|
---|
80 | menu "Create" and then "Insert Shared Action...". Domino Designer will show you
|
---|
81 | a list of Shared Actions. Select the Action "SPAM" and press "Insert" and then
|
---|
82 | press "Done". Now close the Folder and save it.
|
---|
83 |
|
---|
84 | Now go to "Folders" and open your Junk Mail folder (the folder is probably named
|
---|
85 | "($JunkMail)" on your installation). At the right part of the screen you should
|
---|
86 | see a list of actions. Select the first action and then select in the menu
|
---|
87 | "Create" and then "Insert Shared Action...". Domino Designer will show you a
|
---|
88 | list of Shared Actions. Select the Action "NOT SPAM" and press "Insert" and then
|
---|
89 | press "Done". Now close the Folder and save it.
|
---|
90 |
|
---|
91 | That's it. Now you should have a new action in your Inbox and one in your Junk
|
---|
92 | Mail folder for reporting SPAM or NON-SPAM.
|
---|
93 |
|
---|
94 | The code here has been tested with sucess on Lotus Notes 6.0.x, 6.5.x, 7.0.x,
|
---|
95 | 8.0.x and 8.5.x. Should you need a more advanced edition of the script where the
|
---|
96 | Lotus Notes client is using TCP/IP to connect to DSPAM and do the SPAM/NONSPAM
|
---|
97 | retraining then let me know. I have a more advanced edition of the script but it
|
---|
98 | uses Java code to connect to DSPAM and that code will only work on Lotus Notes
|
---|
99 | where LS2J is available (Lotus Notes Release 6 and up).
|
---|
100 |
|
---|
101 | Kind Regards from Switzerland,
|
---|
102 |
|
---|
103 | Stevan Bajic <stevan@bajic.ch>
|
---|
104 | %END REM
|
---|
105 |
|
---|
106 | Option Public
|
---|
107 | Option Declare
|
---|
108 | %INCLUDE {lsconst.lss}
|
---|
109 |
|
---|
110 | '// ============================================================================
|
---|
111 | '// Constants
|
---|
112 | '// ============================================================================
|
---|
113 | Const SPAM_ALIAS = {spam@mydomain.local}
|
---|
114 | Const NOTSPAM_ALIAS = {notspam@mydomain.local}
|
---|
115 | Const SPAM_TAG = {[SPAM]}
|
---|
116 | Const HEADER_DSPAM_SIGNATURE = {X_DSPAM_Signature}
|
---|
117 | Const HEADER_DSPAM_RESULT = {X_DSPAM_Result}
|
---|
118 | Const NOTES_SUBJECT_FIELDNAME = {Subject}
|
---|
119 | Const NOTES_INBOX_FOLDERNAME = {($Inbox)}
|
---|
120 | Const NOTES_JUNK_FOLDERNAME = {($JunkMail)}
|
---|
121 | '// ============================================================================
|
---|
122 |
|
---|
123 | Public Function fnDSPAMReport ( ByVal szType As String ) As Integer
|
---|
124 | '// Module: fnDSPAMReport
|
---|
125 | '// Author: Stevan Bajic (stevan@bajic.ch)
|
---|
126 | '// Version: v1.0.0
|
---|
127 | '// Last Change Date:
|
---|
128 | '// Description:
|
---|
129 | '// Revision History:
|
---|
130 |
|
---|
131 | '// =======================================================================
|
---|
132 | '// Declare ModuleName for Global ErrorTrapping, etc.
|
---|
133 | '// =======================================================================
|
---|
134 | Dim szModuleName As String
|
---|
135 | szModuleName = {fnDSPAMReport}
|
---|
136 | '// =======================================================================
|
---|
137 |
|
---|
138 | '// =======================================================================
|
---|
139 | '// Use ErrorHandler for Error-Trapping
|
---|
140 | '// =======================================================================
|
---|
141 | On Error Goto ErrorHandler
|
---|
142 | '// =======================================================================
|
---|
143 |
|
---|
144 | '// =======================================================================
|
---|
145 | '// Initialize default returnvalue
|
---|
146 | '// =======================================================================
|
---|
147 | fnDSPAMReport = False
|
---|
148 | '// =======================================================================
|
---|
149 |
|
---|
150 | '// =======================================================================
|
---|
151 | '// Parameter checking
|
---|
152 | '// =======================================================================
|
---|
153 | If Not ( UCase$ ( szType ) = {SPAM} Or UCase$ ( szType ) = {HAM} Or UCase$ ( szType ) = {NONSPAM} Or UCase$ ( szType ) = {JUNK} Or UCase$ ( szType ) = {NONJUNK} ) Then
|
---|
154 | Messagebox {The type "} + szType + {" is not a recognized report type.} , MB_OK + MB_ICONEXCLAMATION , {DSPAM spam/ham report }
|
---|
155 | Exit Function
|
---|
156 | End If
|
---|
157 | '// =======================================================================
|
---|
158 |
|
---|
159 | '// =======================================================================
|
---|
160 | '// Declare variables for this module
|
---|
161 | '// =======================================================================
|
---|
162 | Dim objSession As NotesSession
|
---|
163 | Dim objCurrentDatabase As NotesDatabase
|
---|
164 | Dim objDocumentCollection As NotesDocumentCollection
|
---|
165 | Dim objDocument As NotesDocument
|
---|
166 | Dim objSendDocumentToDSPAM As NotesDocument
|
---|
167 | Dim objUIWorkSpace As NotesUIWorkspace
|
---|
168 | Dim szDSPAMFullSignature As String
|
---|
169 | Dim szDSPAMResult As String
|
---|
170 | Dim szSubject As String
|
---|
171 | Dim intSendStatus As Integer
|
---|
172 | '// =======================================================================
|
---|
173 |
|
---|
174 | '// =======================================================================
|
---|
175 | '// Initialize variables for this module
|
---|
176 | '// =======================================================================
|
---|
177 | Set objUIWorkSpace = New NotesUIWorkspace
|
---|
178 | Set objSession = New NotesSession
|
---|
179 | Set objCurrentDatabase = objSession.CurrentDatabase
|
---|
180 | Set objDocumentCollection = objCurrentDatabase.UnprocessedDocuments
|
---|
181 | '// =======================================================================
|
---|
182 |
|
---|
183 | '// =======================================================================
|
---|
184 | '// Start processing
|
---|
185 | '// =======================================================================
|
---|
186 | If ( objDocumentCollection.Count > 0 ) Then
|
---|
187 | Set objDocument = objDocumentCollection.GetFirstDocument
|
---|
188 | While Not ( objDocument Is Nothing )
|
---|
189 | '// -------------------------------------------------------------
|
---|
190 | '// Get DSPAM Signature
|
---|
191 | If ( objDocument.HasItem ( HEADER_DSPAM_SIGNATURE ) ) Then
|
---|
192 | szDSPAMFullSignature = objDocument.GetFirstItem ( HEADER_DSPAM_SIGNATURE ).Text
|
---|
193 | If Not ( szDSPAMFullSignature Like {[0-9]*[,]*[0-9A-Fa-f]*} ) Then
|
---|
194 | Messagebox {The DSPAM signature "} + szDSPAMFullSignature + {" seems to be not valid.} , MB_OK + MB_ICONEXCLAMATION , {DSPAM spam/ham report }
|
---|
195 | szDSPAMFullSignature= {}
|
---|
196 | End If
|
---|
197 | Else
|
---|
198 | szDSPAMFullSignature = {}
|
---|
199 | End If
|
---|
200 | '// -------------------------------------------------------------
|
---|
201 | '// Get DSPAM Result
|
---|
202 | If ( objDocument.HasItem ( HEADER_DSPAM_RESULT ) ) Then
|
---|
203 | szDSPAMResult = objDocument.GetFirstItem ( HEADER_DSPAM_RESULT ).Text
|
---|
204 | Else
|
---|
205 | szDSPAMResult = {}
|
---|
206 | End If
|
---|
207 | '// -------------------------------------------------------------
|
---|
208 | '// Get Subject
|
---|
209 | If ( objDocument.HasItem ( NOTES_SUBJECT_FIELDNAME ) ) Then
|
---|
210 | szSubject = objDocument.GetFirstItem ( NOTES_SUBJECT_FIELDNAME ).Text
|
---|
211 | While InStr ( 1 , szSubject , SPAM_TAG , 5 ) > 0
|
---|
212 | szSubject = Left$ ( szSubject , InStr ( 1 , szSubject , SPAM_TAG , 5 ) - 1 ) + Mid$ ( szSubject , InStr ( 1 , szSubject , SPAM_TAG , 5 ) + Len ( SPAM_TAG ) + 1 )
|
---|
213 | Wend
|
---|
214 | Else
|
---|
215 | szSubject = {}
|
---|
216 | End If
|
---|
217 | '// -------------------------------------------------------------
|
---|
218 | If Not ( szDSPAMFullSignature = {} ) Then
|
---|
219 | Set objSendDocumentToDSPAM = objCurrentDatabase.CreateDocument
|
---|
220 | If ( UCase$ ( szType ) = {SPAM} Or UCase$ ( szType ) = {JUNK} ) Then
|
---|
221 | '// ===================================================
|
---|
222 | '// Retrain as SPAM
|
---|
223 | '// ===================================================
|
---|
224 | With objSendDocumentToDSPAM
|
---|
225 | Call .ReplaceItemValue ( {Form} , {Memo} )
|
---|
226 | Call .ReplaceItemValue ( {SaveMessageOnSend} , False )
|
---|
227 | Call .ReplaceItemValue ( {Body} , {!DSPAM:} + szDSPAMFullSignature + {!} )
|
---|
228 | intSendStatus = .Send ( False , SPAM_ALIAS )
|
---|
229 | End With
|
---|
230 | If ( intSendStatus = True ) Then
|
---|
231 | With objDocument
|
---|
232 | Call .ReplaceItemValue ( NOTES_SUBJECT_FIELDNAME , SPAM_TAG + { } + szSubject )
|
---|
233 | Call .ReplaceItemValue ( HEADER_DSPAM_RESULT , {Spam} )
|
---|
234 | If ( .Save ( True , False , False ) = True ) Then
|
---|
235 | Call .PutInFolder ( NOTES_JUNK_FOLDERNAME , True )
|
---|
236 | Call .RemoveFromFolder ( NOTES_INBOX_FOLDERNAME )
|
---|
237 | End If
|
---|
238 | End With
|
---|
239 | End If
|
---|
240 | '// ===================================================
|
---|
241 | Else
|
---|
242 | '// ===================================================
|
---|
243 | '// Retrain as NONSPAM
|
---|
244 | '// ===================================================
|
---|
245 | With objSendDocumentToDSPAM
|
---|
246 | Call .ReplaceItemValue ( {Form} , {Memo} )
|
---|
247 | Call .ReplaceItemValue ( {SaveMessageOnSend} , False )
|
---|
248 | Call .ReplaceItemValue ( {Body} , {!DSPAM:} + szDSPAMFullSignature + {!} )
|
---|
249 | intSendStatus = .Send ( False , NOTSPAM_ALIAS )
|
---|
250 | End With
|
---|
251 | If ( intSendStatus = True ) Then
|
---|
252 | With objDocument
|
---|
253 | Call .ReplaceItemValue ( NOTES_SUBJECT_FIELDNAME , szSubject )
|
---|
254 | Call .ReplaceItemValue ( HEADER_DSPAM_RESULT , {Innocent} )
|
---|
255 | If ( .Save ( True , False , False ) = True ) Then
|
---|
256 | Call .PutInFolder ( NOTES_INBOX_FOLDERNAME , True )
|
---|
257 | Call .RemoveFromFolder ( NOTES_JUNK_FOLDERNAME )
|
---|
258 | End If
|
---|
259 | End With
|
---|
260 | End If
|
---|
261 | '// ===================================================
|
---|
262 | End If
|
---|
263 | Else
|
---|
264 | Print {Skipping message with UNID "} + objDocument.UniversalID + {" because of missing DSPAM headers}
|
---|
265 | End If
|
---|
266 | '// -------------------------------------------------------------
|
---|
267 | Set objDocument = objDocumentCollection.GetNextDocument ( objDocument )
|
---|
268 | '// -------------------------------------------------------------
|
---|
269 | Wend
|
---|
270 | Call objUIWorkSpace.ReloadWindow
|
---|
271 | End If
|
---|
272 | '// =======================================================================
|
---|
273 |
|
---|
274 | '// =======================================================================
|
---|
275 | '// Set return value for this module
|
---|
276 | '// =======================================================================
|
---|
277 | fnDSPAMReport = True
|
---|
278 | '// =======================================================================
|
---|
279 |
|
---|
280 | '// =======================================================================
|
---|
281 | '// Exit the module
|
---|
282 | '// =======================================================================
|
---|
283 | Exit Function
|
---|
284 | '// =======================================================================
|
---|
285 |
|
---|
286 | ErrorHandler:
|
---|
287 | Select Case fnErrorHandler ( Error$ , Err , Erl , szModuleName )
|
---|
288 | Case 0
|
---|
289 | Exit Function
|
---|
290 | Case 1
|
---|
291 | Resume Next
|
---|
292 | Case Else
|
---|
293 | Resume Next
|
---|
294 | End Select
|
---|
295 | End Function
|
---|
296 | Private Function fnErrorHandler ( Byval szErrorText As String , Byval lngErrorNumber As Long , Byval lngErrorLine As Long , Byval szModuleName As String ) As Integer
|
---|
297 | '// Module: fnErrorHandler
|
---|
298 | '// Author: Stevan Bajic (stevan@bajic.ch)
|
---|
299 | '// Version: v1.0.0
|
---|
300 | '// Last Change Date:
|
---|
301 | '// Description: A sort of Global ErrorHandler
|
---|
302 | '// Revision History:
|
---|
303 | '// Return Values:
|
---|
304 | '// 0 = Exit calling Function/Sub
|
---|
305 | '// 1 = Resume Next
|
---|
306 |
|
---|
307 | '// =======================================================================
|
---|
308 | '// We don't trap erros in this module
|
---|
309 | '// =======================================================================
|
---|
310 | On Error Resume Next
|
---|
311 | '// =======================================================================
|
---|
312 |
|
---|
313 | '// =======================================================================
|
---|
314 | '// Initialize default returnvalue
|
---|
315 | '// =======================================================================
|
---|
316 | fnErrorHandler = 1
|
---|
317 | '// =======================================================================
|
---|
318 |
|
---|
319 | '// =======================================================================
|
---|
320 | '// Declare variables for this module
|
---|
321 | '// =======================================================================
|
---|
322 | Dim objSession As New NotesSession
|
---|
323 | Dim szLogPrefix As String
|
---|
324 | '// =======================================================================
|
---|
325 |
|
---|
326 | '// =======================================================================
|
---|
327 | '// Initialize variables for this module
|
---|
328 | '// =======================================================================
|
---|
329 | szLogPrefix = {}
|
---|
330 | If ( objSession.CurrentAgent Isa {NotesAgent} ) Then
|
---|
331 | szLogPrefix = szLogPrefix + {[Agent Name: } + objSession.CurrentAgent.Name + {]}
|
---|
332 | szLogPrefix = szLogPrefix + {[Agent Server Name: } + objSession.CurrentAgent.ServerName + {]}
|
---|
333 | End If
|
---|
334 | szLogPrefix = szLogPrefix + {[} + CStr ( GetThreadInfo ( LSI_THREAD_PROC ) ) + { <- } + CStr ( LSI_Info ( 12 ) ) + {]}
|
---|
335 | '// =======================================================================
|
---|
336 |
|
---|
337 | '// =======================================================================
|
---|
338 | '// Start processing
|
---|
339 | '// =======================================================================
|
---|
340 | Print szLogPrefix + { --> "} + szModuleName + {" (N=} + CStr ( lngErrorNumber ) + { L=} + CStr ( lngErrorLine ) + {) E=} + szErrorText
|
---|
341 | '// =======================================================================
|
---|
342 |
|
---|
343 | '// =======================================================================
|
---|
344 | '// Exit the module
|
---|
345 | '// =======================================================================
|
---|
346 | Exit Function
|
---|
347 | '// =======================================================================
|
---|
348 |
|
---|
349 | End Function
|
---|