set_default_setting('LOCAL_TIME_FILE', None)
set_default_setting('ENABLE_REBOOT', False)
set_default_setting('SMTP_TIMEOUT', 60)
- set_default_setting('NOTIFY_MEDIA_TIMESPAN', 5)
set_default_setting('ZIP_TIMEOUT', 500)
length = len(sys.argv) - 1
conn.quit()
-def make_message(subject, message, camera_id, moment, callback):
+def make_message(subject, message, camera_id, moment, timespan, callback):
camera_config = config.get_camera(camera_id)
def on_media_files(media_files):
timestamp = time.mktime(moment.timetuple())
- media_files = [m for m in media_files if abs(m['timestamp'] - timestamp) < settings.NOTIFY_MEDIA_TIMESPAN] # filter out non-recent media files
+ media_files = [m for m in media_files if abs(m['timestamp'] - timestamp) < timespan] # filter out non-recent media files
media_files.sort(key=lambda m: m['timestamp'], reverse=True)
media_files = [os.path.join(camera_config['target_dir'], re.sub('^/', '', m['path'])) for m in media_files]
callback(s, m, media_files)
- time.sleep(settings.NOTIFY_MEDIA_TIMESPAN)
+ if not timespan:
+ return on_media_files([])
+
+ time.sleep(timespan) # give motion some time to create motion pictures
mediafiles.list_media(camera_config, media_type='picture', callback=on_media_files)
def print_usage():
- print 'Usage: sendmail.py <server> <port> <account> <password> <tls> <to> <msg_id> <camera_id> <moment> <frames>'
+ print 'Usage: sendmail.py <server> <port> <account> <password> <tls> <to> <msg_id> <camera_id> <moment> <frames> [timespan]'
if __name__ == '__main__':
msg_id = sys.argv[7]
camera_id = sys.argv[8]
moment = sys.argv[9]
+ try:
+ timespan = int(sys.argv[10])
+
+ except:
+ timespan = 5
message = messages.get(msg_id)
subject = subjects.get(msg_id)
logging.debug('camera_id = %s' % camera_id)
logging.debug('moment = %s' % moment.strftime('%Y-%m-%d %H:%M:%S'))
logging.debug('smtp timeout = %d' % settings.SMTP_TIMEOUT)
+ logging.debug('timespan = %d' % timespan)
if not to:
logging.info('no email address specified')
def ioloop_timeout():
io_loop.stop()
- make_message(subject, message, camera_id, moment, on_message)
+ make_message(subject, message, camera_id, moment, timespan, on_message)
io_loop.add_timeout(datetime.timedelta(seconds=settings.SMTP_TIMEOUT), ioloop_timeout)
io_loop.start()
# the timeout in seconds to use when talking to a SMTP server
SMTP_TIMEOUT = 60
-# the interval in seconds to consider around the moment of the event when attaching media files to notifications
-NOTIFY_MEDIA_TIMESPAN = 5
-
# the time to wait for zip file creation
ZIP_TIMEOUT = 500
import logging
import os.path
import re
+import shlex
from collections import OrderedDict
send_mail_path = os.path.abspath(send_mail_path)
emails = re.sub('\\s', '', ui['email_notifications_addresses'])
- on_event_start.append('%(script)s "%(server)s" "%(port)s" "%(account)s" "%(password)s" "%(tls)s" "%(to)s" "motion_start" "%%t" "%%Y-%%m-%%dT%%H:%%M:%%S"' % {
+ on_event_start.append('%(script)s "%(server)s" "%(port)s" "%(account)s" "%(password)s" "%(tls)s" "%(to)s" "motion_start" "%%t" "%%Y-%%m-%%dT%%H:%%M:%%S" "%(timespan)s"' % {
'script': send_mail_path,
'server': ui['email_notifications_smtp_server'],
'port': ui['email_notifications_smtp_port'],
'account': ui['email_notifications_smtp_account'],
'password': ui['email_notifications_smtp_password'],
'tls': ui['email_notifications_smtp_tls'],
- 'to': emails})
+ 'to': emails,
+ 'timespan': ui['email_notifications_picture_time_span']})
if ui['web_hook_notifications_enabled']:
web_hook_path = os.path.join(settings.PROJECT_PATH, 'webhook.py')
command_notifications = []
for e in on_event_start:
if e.count('sendmail.py') and e.count('motion_start'):
- e = e.replace('"', '').split(' ')
- if len(e) != 10:
+ e = shlex.split(e)
+ if len(e) < 10:
continue
ui['email_notifications_enabled'] = True
ui['email_notifications_smtp_password'] = e[4]
ui['email_notifications_smtp_tls'] = e[5].lower() == 'true'
ui['email_notifications_addresses'] = e[6]
+ try:
+ ui['email_notifications_picture_time_span'] = int(e[10])
+
+ except:
+ ui['email_notifications_picture_time_span'] = 5
elif e.count('webhook.py'):
- e = e.replace('"', '').split(' ')
+ e = shlex.split(e)
if len(e) != 3:
continue
makeNumberValidator($('#postCaptureEntry'), 0, 100, false, false, true);
makeNumberValidator($('#minimumMotionFramesEntry'), 1, 1000, false, false, true);
makeNumberValidator($('#smtpPortEntry'), 1, 65535, false, false, true);
+ makeNumberValidator($('#emailPictureTimeSpan'), 0, 60, false, false, true);
/* time validators */
makeTimeValidator($('#mondayFromEntry'));
$('#smtpAccountEntry').parents('tr:eq(0)').each(markHide);
$('#smtpPasswordEntry').parents('tr:eq(0)').each(markHide);
$('#smtpTlsSwitch').parents('tr:eq(0)').each(markHide);
+ $('#emailPictureTimeSpan').parents('tr:eq(0)').each(markHide);
}
if (!$('#webHookNotificationsSwitch').get(0).checked) {
'email_notifications_smtp_account': $('#smtpAccountEntry').val(),
'email_notifications_smtp_password': $('#smtpPasswordEntry').val(),
'email_notifications_smtp_tls': $('#smtpTlsSwitch')[0].checked,
+ 'email_notifications_picture_time_span': $('#emailPictureTimeSpan').val(),
'web_hook_notifications_enabled': $('#webHookNotificationsSwitch')[0].checked,
'web_hook_notifications_url': $('#webHookUrlEntry').val(),
'web_hook_notifications_http_method': $('#webHookHttpMethodSelect').val(),
$('#smtpAccountEntry').val(dict['email_notifications_smtp_account']);
$('#smtpPasswordEntry').val(dict['email_notifications_smtp_password']);
$('#smtpTlsSwitch')[0].checked = dict['email_notifications_smtp_tls'];
+ $('#emailPictureTimeSpan').val(dict['email_notifications_picture_time_span']);
$('#webHookNotificationsSwitch')[0].checked = dict['web_hook_notifications_enabled'];
$('#webHookUrlEntry').val(dict['web_hook_notifications_url']);
$('#webHookHttpMethodSelect').val(dict['web_hook_notifications_http_method']);
<td class="settings-item-value"><input type="checkbox" class="styled notifications" id="smtpTlsSwitch"></td>
<td><span class="help-mark" title="enable this if your SMTP server requires TLS (Gmail needs this to be enabled)">?</span></td>
</tr>
+ <tr class="settings-item advanced-setting">
+ <td class="settings-item-label"><span class="settings-item-label">Attached Pictures Time Span</span></td>
+ <td class="settings-item-value"><input type="text" class="number styled notifications" id="emailPictureTimeSpan"><span class="settings-item-unit">seconds</span></td>
+ <td><span class="help-mark" title="defines the picture search time interval to use when creating email attachments (higher values generate emails with more pictures at the cost of an increased notification delay)">?</span></td>
+ </tr>
<tr class="settings-item advanced-setting">
<td colspan="100"><div class="settings-item-separator"></div></td>
</tr>