****************************************************************************************************************************
 Nvamailscan.nve
****************************************************************************************************************************

To start this module from the mailserver program following entries need to be made in nvalarm.ini

[nvaemailin]
StartModuleForFrom1=srv-hs-mailgate-p.bvch.ch
StartModule1=nvamailscan

Specify a part of a from address to start this module. The module is then only started if the sender
address contains the specfied string. To always start this module, enter @ in StartModuleForFrom1=


All configuration is read from the nvamailscan.ini and modulename as section ( [nvamailscan] ).

If this module needs to be run with a different configuration for an other sender address, then copy
the nvamailscan.nve module ( Example nvamailscan2.nve ) and a new section with the module name
( [nvamailscan2] ) is created automatically.

The scantext which is used to compare with the alarmnames in the database is take from the subOect or with 
regexp from the body text. This is defined with the flag ScanForSubOect= in the ini.
If this flag is 1, the received subOect is used to scan in db. If not active the body text is used.




----------------------------------------------------------------------------------------------------------------------------
Example of ini file:
----------------------------------------------------------------------------------------------------------------------------

[nvamailscan]
DefaultAlarm=8000
ScanFromAlarm=8001
ScanToAlarm=8099
ScanForSubject=0
ScanRegexp=LZC_1:([0-9]*).*;TYP:([A-Za-z][A-Za-z]*)*$
ScanLayout=Zone \1_\2
AddTextToEndOfLineInBody=
ProcRegexp=.*IDE_1:([0-9]*).*LZC_1:([0-9]*).*
ProcLayout=postie -host:10.26.1.145 -to:\1@srv-hs-mailgate-p.bvch.ch -from:Personenschutz@bvch.ch -s:Meldung -msg:"Ihr Handalarm in Zone \2 wurde ausgelöst."
AdditionalProcRegexp=
AdditionalProcLayout=
MessageRegexp=
MessageLayout=
Message1Regexp=
Message1Layout=
Message2Regexp=
Message2Layout=
WatchDogAlarmKey=0
WatchDogTextRegexp=
WatchDogTextLayout=
DoNotStartAlarmIfSubOectContains=Status
ZnlyStartAlarmIfSubOectContains=
StartModuleIfNoAlarm=
DoNotStartAlarmIfBodyContains=
ZnlyStartAlarmIfBodyContains=

[WatchDogText]
WatchDog_XXX=9902
WatchDog_YYY=9903
WatchDog_ZZZ=9904


----------------------------------------------------------------------------------------------------------------------------
Regexp to get scantext from mail bodytext
----------------------------------------------------------------------------------------------------------------------------


The regexp is specified in the ini settings. With the regexp the data needed for the text to scan in db can be extracted from
the mail body text.


Example regexp to use LZC_1 and TYP as scantext:

Body text:
IDE_1:9984;IDE_2:Telefonie 1;LZC_1:052;LZC_2:EG - Vorplatz Schulungsraum 028;TYP:Handalarm

ScanRegexp=LZC_1:([0-9]*).*;TYP:([A-Za-z][A-Za-z]*)*$
ScanLayout=Zone \1_\2

The scantext would be "Zone 052_Handalarm"




----------------------------------------------------------------------------------------------------------------------------
Start special command and additional command
----------------------------------------------------------------------------------------------------------------------------

Special command after scan regexp, is also specifed in ini-file. Text can be extracted from the body and used in the 
process command. This process is started after the alarm. Leave the entries empty in the ini, if no process should
be started.

Example of special process settings:

Body text:
IDE_1:9984;IDE_2:Telefonie 1;LZC_1:052;LZC_2:EG - Vorplatz Schulungsraum 028;TYP:Handalarm

ProcRegexp=.*IDE_1:([0-9]*).*LZC_1:([0-9]*).*
ProcLayout=postie -host:10.26.1.145 -to:\1@srv-hs-mailgate-p.bvch.ch -from:Personenschutz@bvch.ch -s:Meldung -msg:"Ihr Handalarm in Zone \2 wurde ausgelöst."

This will send an email by postie to the number specified in IDE_1: and adds the zone to the body text.

The AdditionalProcRegexp is for an additional process which needs to be started


----------------------------------------------------------------------------------------------------------------------------
Extract message
----------------------------------------------------------------------------------------------------------------------------

The message for the alarm can also be extracted from the mail body text with regexp. For each message ( SMS pager uui message,
display-message1 before answer and display message2 after answer) a regexp can be defined in the ini-file. If no message is defined
the message is used from the alarmkey. If a regexp for the sms message is defined but none for the displaymessage, then the alarm messages 
are used for the display (nvamsg2.ini and nvamsg2.ini).
In the Layout key a pre, post message and the postion can be defined.

Example for main message:

Body text:
IDE_1:9984;IDE_2:Telefonie 1;LZC_1:052;LZC_2:EG - Vorplatz Schulungsraum 028;TYP:Handalarm

MessageRegexp=LZC_1:([0-9]*).*;LZC_2:([A-Za-z][A-Za-z]*.*);TYP:([A-Za-z][A-Za-z]*)*$
MessageLayout=Alarm \1 \2 \3

Extracted message is:
Message=Alarm 052 EG - Vorplatz Schulungsraum 028 Handalarm



----------------------------------------------------------------------------------------------------------------------------
WatchDog for emails
----------------------------------------------------------------------------------------------------------------------------

The watchdog alarm specified in the ini needs to exist as watchdog alarm in the db. Therefor add the alarm and set the 
type ( alarm-icon ) to watchdog alarm. Set to wdog event set by application and enter invtervall, wait after alarm and comment.
If no email was received durring the specified intervall, the alarm is started. The email needs to start the nvamailscan module,
for the watchdog event to be set. The watchdog event is set for every incoming email which uses the mailscan module.


Specific WatchDog Events:

If the watchdog event of a specified alarm needs to be set only if a specific mail is received, then the watchdog regexp can be 
used. With this regular expresion a watchdog text can be extracted from the received bodytext (not scantext). The extracted watchdog
text can be the same as the scantext or a part of the scantext.
This watchdog text is used to get the alarmkey of the watchdog alarm of which the event is set. The watchdog text can not contain any 
special characters or blanks and needs to be specified under the [WatchDogText] in the ini-file.
If a valid watchdog alarmkey was specified for the watchdogtext, then the watchdog event for this alarm is updated and no alarm is launched.

[WatchDogText]
WatchDog_XXX=9902
WatchDog_YYY=9903
WatchDog_ZZZ=9904



----------------------------------------------------------------------------------------------------------------------------
Logfile
----------------------------------------------------------------------------------------------------------------------------

All logs of the module are written to the log-directory and name of the module .log ( nvamailscan.log )

