source: npl/mailserver/dspam/dspam-3.10.2/contrib/lotus_notes/libDSPAMReporting.lss

Last change on this file was c5c522c, checked in by Edwin Eefting <edwin@datux.nl>, 8 years ago

initial commit, transferred from cleaned syn3 svn tree

  • Property mode set to 100644
File size: 17.0 KB
Line 
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
21This LotusScript library uses the spam/nonspam alias functionality of DSPAM to
22retrain messages as SPAM or as NONSPAM.
23
24How to make this work?
25----------------------
26Open your mail database (or the mail template) with the Domino Designer and go
27to "Shared Code", "Script Libraries". Press the action "New LotusScript Library"
28and in the new created Script Library press in the right pane (there where you
29would normally type your LotusScript code) the right mouse button and then
30select "Import...". Browse the file system and select this file here. You will
31get a dialog box with the title "LotusScript Import Options" asking you if it
32should replace existing code. Please answer with "Yes to All".
33Now the code is imported and you should go into the "(Declarations)" and change
34there your SPAM and HAM alias. The line you should change are:
35Const SPAM_ALIAS                                = {spam@mydomain.local}
36Const NOTSPAM_ALIAS                             = {notspam@mydomain.local}
37
38Just enter the SPAM/NOTSPAM alias you are using in your DSPAM instalaltion.
39
40Should you have set the SPAM tag to be anything else then "[SPAM]" the you need
41to change the SPAM_TAG as well. The line you should change is:
42Const SPAM_TAG                                  = {[SPAM]}
43
44After you have changed those lines you can close the Script Library and save it.
45The Domino Designer will ask you how to name that new created Script Library.
46Use something like "libDSPAMReporting" or anything you like. Now you need to go
47into "Shared Code", "Actions" and press the button "New Shared Action". Domino
48Designer will create a new Shared Action and show you a property box. In that
49property box set the Name entry to "SPAM" and the Label to "SPAM" as well. For
50the Type select "Button" and select "Include action in Action bar" and "Include
51action in Action menu". For the Icon select the type to be "Notes" and Location
52to be "Left" and for the icon image anything you like (I use the X wich is the
53last icon in the first row). Close now the property box and select the type of
54the Shared Action to be LotusScript. Then select (Options) and type:
55Use "libDSPAMReporting"
56
57Then select the event "Click" and type:
58Sub Click(Source As Button)
59        Call fnDSPAMReport ( {SPAM} )
60End Sub
61
62Save the Shared Action and press again on "New Shared Action". Domino Designer
63will create a new Shared Action and show you a property box. In that property
64box set the Name entry to "NOT SPAM" and the Label to "NOT SPAM" as well. For
65the Type select "Button" and select "Include action in Action bar" and "Include
66action in Action menu". For the Icon select the type to be "Notes" and Location
67to be "Left" and for the icon image anything you like (I use the check mark wich
68is the second last icon in the first row). Close now the property box and select
69the type of the Shared Action to be LotusScript. Then select (Options) and type:
70Use "libDSPAMReporting"
71
72Then select the event "Click" and type:
73Sub Click(Source As Button)
74        Call fnDSPAMReport ( {NOTSPAM} )
75End Sub
76
77Save the Shared Action. Now go to "Folders" and open your INBOX (the folder is
78probably named "($Inbox)" on your installation). At the right part of the screen
79you should see a list of actions. Select the first action and then select in the
80menu "Create" and then "Insert Shared Action...". Domino Designer will show you
81a list of Shared Actions. Select the Action "SPAM" and press "Insert" and then
82press "Done". Now close the Folder and save it.
83
84Now 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
86see 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
88list of Shared Actions. Select the Action "NOT SPAM" and press "Insert" and then
89press "Done". Now close the Folder and save it.
90
91That's it. Now you should have a new action in your Inbox and one in your Junk
92Mail folder for reporting SPAM or NON-SPAM.
93
94The code here has been tested with sucess on Lotus Notes 6.0.x, 6.5.x, 7.0.x,
958.0.x and 8.5.x. Should you need a more advanced edition of the script where the
96Lotus Notes client is using TCP/IP to connect to DSPAM and do the SPAM/NONSPAM
97retraining then let me know. I have a more advanced edition of the script but it
98uses Java code to connect to DSPAM and that code will only work on Lotus Notes
99where LS2J is available (Lotus Notes Release 6 and up).
100
101Kind Regards from Switzerland,
102
103Stevan Bajic <stevan@bajic.ch>
104%END REM
105
106Option Public
107Option Declare
108%INCLUDE {lsconst.lss}
109
110'// ============================================================================
111'// Constants
112'// ============================================================================
113Const SPAM_ALIAS                                = {spam@mydomain.local}
114Const NOTSPAM_ALIAS                             = {notspam@mydomain.local}
115Const SPAM_TAG                                  = {[SPAM]}
116Const HEADER_DSPAM_SIGNATURE            = {X_DSPAM_Signature}
117Const HEADER_DSPAM_RESULT               = {X_DSPAM_Result}
118Const NOTES_SUBJECT_FIELDNAME           = {Subject}
119Const NOTES_INBOX_FOLDERNAME            = {($Inbox)}
120Const NOTES_JUNK_FOLDERNAME             = {($JunkMail)}
121'// ============================================================================
122
123Public 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       
286ErrorHandler:
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
295End Function
296Private 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
349End Function
Note: See TracBrowser for help on using the repository browser.