Beispiel #1
0
def main(parser, args):
    import meyectl
    
    options = parse_options(parser, args)
    
    meyectl.configure_logging('webhook', options.log_to_file)
    meyectl.configure_tornado()

    logging.debug('hello!')
    logging.debug('method = %s' % options.method)
    logging.debug('url = %s' % options.url)
    
    if options.method == 'POST':
        parts = urlparse.urlparse(options.url)
        data = parts.query

    else:
        data = None

    request = urllib2.Request(options.url, data)
    try:
        urllib2.urlopen(request, timeout=settings.REMOTE_REQUEST_TIMEOUT)
        logging.debug('webhook successfully called')
    
    except Exception as e:
        logging.error('failed to call webhook: %s' % e)

    logging.debug('bye!')
Beispiel #2
0
def main(parser, args):
    import meyectl

    options = parse_options(parser, args)

    meyectl.configure_logging('webhook', options.log_to_file)
    meyectl.configure_tornado()

    logging.debug('hello!')
    logging.debug('method = %s' % options.method)
    logging.debug('url = %s' % options.url)

    if options.method == 'POST':
        parts = urlparse.urlparse(options.url)
        data = parts.query

    else:
        data = None

    request = urllib2.Request(options.url, data)
    try:
        urllib2.urlopen(request, timeout=settings.REMOTE_REQUEST_TIMEOUT)
        logging.debug('webhook successfully called')

    except Exception as e:
        logging.error('failed to call webhook: %s' % e)

    logging.debug('bye!')
Beispiel #3
0
def main(parser, args):
    import meyectl

    options = parse_options(parser, args)

    meyectl.configure_logging('sendmail', options.log_to_file)
    meyectl.configure_tornado()

    logging.debug('hello!')

    options.port = int(options.port)
    options.tls = options.tls.lower() == 'true'
    options.timespan = int(options.timespan)
    message = messages.get(options.msg_id)
    subject = subjects.get(options.msg_id)
    options.moment = datetime.datetime.strptime(options.moment,
                                                '%Y-%m-%dT%H:%M:%S')

    logging.debug('server = %s' % options.server)
    logging.debug('port = %s' % options.port)
    logging.debug('account = %s' % options.account)
    logging.debug('password = ******')
    logging.debug('server = %s' % options.server)
    logging.debug('tls = %s' % str(options.tls).lower())
    logging.debug('to = %s' % options.to)
    logging.debug('msg_id = %s' % options.msg_id)
    logging.debug('camera_id = %s' % options.camera_id)
    logging.debug('moment = %s' % options.moment.strftime('%Y-%m-%d %H:%M:%S'))
    logging.debug('smtp timeout = %d' % settings.SMTP_TIMEOUT)
    logging.debug('timespan = %d' % options.timespan)

    to = [t.strip() for t in re.split('[,;| ]', options.to)]
    to = [t for t in to if t]

    io_loop = IOLoop.instance()

    def on_message(subject, message, files):
        try:
            send_mail(options.server, options.port, options.account,
                      options.password, options.tls, options.to, subject,
                      message, files)
            logging.info('email sent')

        except Exception as e:
            logging.error('failed to send mail: %s' % e, exc_info=True)

        io_loop.stop()

    def ioloop_timeout():
        io_loop.stop()

    make_message(subject, message, options.camera_id, options.moment,
                 options.timespan, on_message)

    io_loop.add_timeout(datetime.timedelta(seconds=settings.SMTP_TIMEOUT),
                        ioloop_timeout)
    io_loop.start()

    logging.debug('bye!')
Beispiel #4
0
def main(parser, args):
    import meyectl
    
    # the motion daemon overrides SIGCHLD,
    # so we must restore it here,
    # or otherwise media listing won't work
    signal.signal(signal.SIGCHLD,signal.SIG_DFL)

    options = parse_options(parser, args)
    
    meyectl.configure_logging('sendmail', options.log_to_file)

    logging.debug('hello!')

    options.port = int(options.port) 
    options.tls = options.tls.lower() == 'true'
    options.timespan = int(options.timespan)
    message = messages.get(options.msg_id)
    subject = subjects.get(options.msg_id)
    options.moment = datetime.datetime.strptime(options.moment, '%Y-%m-%dT%H:%M:%S')
    options.password = options.password.replace('\\;', ';') # unescape password
    
    # do not wait too long for media list,
    # email notifications are critical
    settings.LIST_MEDIA_TIMEOUT = 10
    
    camera_id = motionctl.thread_id_to_camera_id(options.thread_id)

    logging.debug('server = %s' % options.server)
    logging.debug('port = %s' % options.port)
    logging.debug('account = %s' % options.account)
    logging.debug('password = ******')
    logging.debug('server = %s' % options.server)
    logging.debug('tls = %s' % str(options.tls).lower())
    logging.debug('to = %s' % options.to)
    logging.debug('msg_id = %s' % options.msg_id)
    logging.debug('thread_id = %s' % options.thread_id)
    logging.debug('camera_id = %s' % camera_id)
    logging.debug('moment = %s' % options.moment.strftime('%Y-%m-%d %H:%M:%S'))
    logging.debug('smtp timeout = %d' % settings.SMTP_TIMEOUT)
    logging.debug('timespan = %d' % options.timespan)
    
    to = [t.strip() for t in re.split('[,;| ]', options.to)]
    to = [t for t in to if t]

    def on_message(subject, message, files):
        try:
            send_mail(options.server, options.port, options.account, options.password,
                    options.tls, to, subject, message, files or [])
            logging.info('email sent')

        except Exception as e:
            logging.error('failed to send mail: %s' % e, exc_info=True)

        logging.debug('bye!')
    
    make_message(subject, message, camera_id, options.moment, options.timespan, on_message)
Beispiel #5
0
def main(parser, args):
    import meyectl
    
    options = parse_options(parser, args)
    
    meyectl.configure_logging('sendmail', options.log_to_file)
    meyectl.configure_tornado()

    logging.debug('hello!')

    options.port = int(options.port) 
    options.tls = options.tls.lower() == 'true'
    options.timespan = int(options.timespan)
    message = messages.get(options.msg_id)
    subject = subjects.get(options.msg_id)
    options.moment = datetime.datetime.strptime(options.moment, '%Y-%m-%dT%H:%M:%S')
    
    logging.debug('server = %s' % options.server)
    logging.debug('port = %s' % options.port)
    logging.debug('account = %s' % options.account)
    logging.debug('password = ******')
    logging.debug('server = %s' % options.server)
    logging.debug('tls = %s' % str(options.tls).lower())
    logging.debug('to = %s' % options.to)
    logging.debug('msg_id = %s' % options.msg_id)
    logging.debug('camera_id = %s' % options.camera_id)
    logging.debug('moment = %s' % options.moment.strftime('%Y-%m-%d %H:%M:%S'))
    logging.debug('smtp timeout = %d' % settings.SMTP_TIMEOUT)
    logging.debug('timespan = %d' % options.timespan)
    
    to = [t.strip() for t in re.split('[,;| ]', options.to)]
    to = [t for t in to if t]

    io_loop = IOLoop.instance()
    
    def on_message(subject, message, files):
        try:
            send_mail(options.server, options.port, options.account, options.password,
                    options.tls, options.to, subject, message, files)
            logging.info('email sent')

        except Exception as e:
            logging.error('failed to send mail: %s' % e, exc_info=True)

        io_loop.stop()
    
    def ioloop_timeout():
        io_loop.stop()
    
    make_message(subject, message, options.camera_id, options.moment, options.timespan, on_message)

    io_loop.add_timeout(datetime.timedelta(seconds=settings.SMTP_TIMEOUT), ioloop_timeout)
    io_loop.start()

    logging.debug('bye!')
Beispiel #6
0
def main(parser, args):
    import meyectl
    
    options = parse_options(parser, args)
    
    meyectl.configure_logging('shell', options.log_to_file)
    meyectl.configure_tornado()

    logging.debug('hello!')
    
    code.interact(local=locals())

    logging.debug('bye!')
Beispiel #7
0
def main(parser, args):
    import meyectl

    options = parse_options(parser, args)

    meyectl.configure_logging('relayevent', options.log_to_file)
    meyectl.configure_tornado()

    logging.debug('hello!')
    logging.debug('event = %s' % options.event)
    logging.debug('thread_id = %s' % options.thread_id)
    if options.filename:
        logging.debug('filename = %s' % options.filename)

    admin_username, admin_password = get_admin_credentials()

    data = {
        '_username': admin_username,
        'thread_id': options.thread_id,
        'event': options.event
    }

    if options.filename:
        data['filename'] = options.filename

    path = '/_relay_event/'
    body = json.dumps(data)

    signature = utils.compute_signature('POST', path, body, admin_password)

    url = 'http://127.0.0.1:%(port)s' + path + '?_signature=' + signature
    url = url % {'port': settings.PORT}

    request = urllib2.Request(url,
                              data=body,
                              headers={'Content-Type': 'application/json'})

    try:
        response = urllib2.urlopen(request)
        response = json.load(response)
        if response.get('error'):
            raise Exception(response['error'])

        logging.debug('event successfully relayed')

    except Exception as e:
        logging.error('failed to relay event: %s' % e)

    logging.debug('bye!')
def main(parser, args):
    import meyectl

    # the motion daemon overrides SIGCHLD,
    # so we must restore it here,
    # or otherwise media listing won't work
    signal.signal(signal.SIGCHLD, signal.SIG_DFL)

    if len(args) == 12:
        # backwards compatibility with older configs lacking "from" field
        _from = 'motionEye on %s <%s>' % (socket.gethostname(),
                                          args[7].split(',')[0])
        args = args[:7] + [_from] + args[7:]

    if not args[7]:
        args[7] = 'motionEye on %s <%s>' % (socket.gethostname(),
                                            args[8].split(',')[0])

    options = parse_options(parser, args)
    print(options)
    meyectl.configure_logging('telegram', options.log_to_file)

    logging.debug('hello!')
    message = messages.get(options.msg_id)

    # do not wait too long for media list,
    # telegram notifications are critical
    settings.LIST_MEDIA_TIMEOUT = settings.LIST_MEDIA_TIMEOUT_TELEGRAM

    camera_id = motionctl.motion_camera_id_to_camera_id(
        options.motion_camera_id)

    logging.debug('timespan = %d' % int(options.timespan))

    def on_message(message, files):
        try:
            print(message)
            logging.info('sending telegram')
            send_message(options.api, options.chatid, message, files or [])
            logging.info('telegram sent')

        except Exception as e:
            logging.error('failed to send telegram: %s' % e, exc_info=True)

        logging.debug('bye!')

    make_message(message, camera_id, options.moment, options.timespan,
                 on_message)
Beispiel #9
0
def main(parser, args):
    import meyectl
    
    options = parse_options(parser, args)
    
    meyectl.configure_logging('relayevent', options.log_to_file)
    meyectl.configure_tornado()

    logging.debug('hello!')
    logging.debug('event = %s' % options.event)
    logging.debug('thread_id = %s' % options.thread_id)
    if options.filename:
        logging.debug('filename = %s' % options.filename)
    
    admin_username, admin_password = get_admin_credentials()
    
    data = {
        '_username': admin_username,
        'thread_id': options.thread_id,
        'event': options.event
    }
    
    if options.filename:
        data['filename'] = options.filename
    
    path = '/_relay_event/'
    body = json.dumps(data)
    
    signature = utils.compute_signature('POST', path, body, admin_password)
    
    url = 'http://127.0.0.1:%(port)s' + path + '?_signature=' + signature
    url = url % {'port': settings.PORT}
    
    request = urllib2.Request(url, data=body, headers={'Content-Type': 'application/json'})
    
    try:
        response = urllib2.urlopen(request)
        response = json.load(response)
        if response.get('error'):
            raise Exception(response['error'])
        
        logging.debug('event successfully relayed')
    
    except Exception as e:
        logging.error('failed to relay event: %s' % e)

    logging.debug('bye!')
Beispiel #10
0
def main(parser, args):
    import meyectl
    import utils

    options = parse_options(parser, args)

    meyectl.configure_logging('webhook', options.log_to_file)
    meyectl.configure_tornado()

    logging.debug('hello!')
    logging.debug('method = %s' % options.method)
    logging.debug('url = %s' % options.url)

    headers = {}
    parts = urllib.parse.urlparse(options.url)
    url = options.url
    data = None

    if options.method == 'POST':
        headers['Content-Type'] = 'text/plain'
        data = ''

    elif options.method == 'POSTf':  # form url-encoded
        headers['Content-Type'] = 'application/x-www-form-urlencoded'
        data = parts.query
        url = options.url.split('?')[0]

    elif options.method == 'POSTj':  # json
        headers['Content-Type'] = 'application/json'
        data = urllib.parse.parse_qs(parts.query)
        data = {k: v[0] for (k, v) in data.items()}
        data = json.dumps(data)
        url = options.url.split('?')[0]

    else:  # GET
        pass

    request = urllib.request.Request(url, data, headers=headers)
    try:
        utils.urlopen(request, timeout=settings.REMOTE_REQUEST_TIMEOUT)
        logging.debug('webhook successfully called')

    except Exception as e:
        logging.error('failed to call webhook: %s' % e)

    logging.debug('bye!')
Beispiel #11
0
def main(parser, args):
    import meyectl
    import utils
    
    options = parse_options(parser, args)
    
    meyectl.configure_logging('webhook', options.log_to_file)
    meyectl.configure_tornado()

    logging.debug('hello!')
    logging.debug('method = %s' % options.method)
    logging.debug('url = %s' % options.url)
    
    headers = {}    
    parts = urlparse.urlparse(options.url)
    url = options.url
    data = None

    if options.method == 'POST':
        headers['Content-Type'] = 'text/plain'
        data = ''

    elif options.method == 'POSTf': # form url-encoded
        headers['Content-Type'] = 'application/x-www-form-urlencoded'
        data = parts.query
        url = options.url.split('?')[0]

    elif options.method == 'POSTj': # json
        headers['Content-Type'] = 'application/json'
        data = urlparse.parse_qs(parts.query)
        data = {k: v[0] for (k, v) in data.iteritems()}
        data = json.dumps(data)
        url = options.url.split('?')[0]

    else: # GET
        pass

    request = urllib2.Request(url, data, headers=headers)
    try:
        utils.urlopen(request, timeout=settings.REMOTE_REQUEST_TIMEOUT)
        logging.debug('webhook successfully called')

    except Exception as e:
        logging.error('failed to call webhook: %s' % e)

    logging.debug('bye!')
Beispiel #12
0
def main(parser, args, command):
    import meyectl

    options = parse_options(parser, args)

    meyectl.configure_logging("motioneye", options.background or options.log_to_file)
    meyectl.configure_tornado()

    if command == "start":
        if options.background:
            daemon = Daemon(pid_file=os.path.join(settings.RUN_PATH, _PID_FILE), run_callback=run)
            daemon.start()

        else:
            run()

    elif command == "stop":
        daemon = Daemon(pid_file=os.path.join(settings.RUN_PATH, _PID_FILE))
        daemon.stop()
Beispiel #13
0
def main(parser, args, command):
    import meyectl
    
    options = parse_options(parser, args)
    
    meyectl.configure_logging('motioneye', options.background or options.log_to_file)
    meyectl.configure_tornado()

    if command == 'start':
        if options.background:
            daemon = Daemon(
                    pid_file=os.path.join(settings.RUN_PATH, _PID_FILE),
                    run_callback=run)
            daemon.start()
            
        else:
            run()

    elif command == 'stop':
        daemon = Daemon(pid_file=os.path.join(settings.RUN_PATH, _PID_FILE))
        daemon.stop()
Beispiel #14
0
def main(parser, args):
    import meyectl

    options = parse_options(parser, args)

    meyectl.configure_logging('relayevent', options.log_to_file)
    meyectl.configure_tornado()

    logging.debug('hello!')
    logging.debug('event = %s' % options.event)
    logging.debug('thread_id = %s' % options.thread_id)

    admin_username, admin_password = get_admin_credentials()

    uri = '/_relay_event/?event=%(event)s&thread_id=%(thread_id)s&_username=%(username)s' % {
        'username': admin_username,
        'thread_id': options.thread_id,
        'event': options.event
    }

    signature = utils.compute_signature('POST', uri, '', admin_password)

    url = 'http://127.0.0.1:%(port)s' + uri + '&_signature=' + signature
    url = url % {'port': settings.PORT}

    try:
        response = urllib.urlopen(url, data='')
        response = json.load(response)
        if response.get('error'):
            raise Exception(response['error'])

        logging.debug('event successfully relayed')

    except Exception as e:
        logging.error('failed to relay event: %s' % e)

    logging.debug('bye!')
Beispiel #15
0
def main(parser, args):
    import meyectl

    options = parse_options(parser, args)

    meyectl.configure_logging("relayevent", options.log_to_file)
    meyectl.configure_tornado()

    logging.debug("hello!")
    logging.debug("event = %s" % options.event)
    logging.debug("thread_id = %s" % options.thread_id)

    admin_username, admin_password = get_admin_credentials()

    path = "/_relay_event/?event=%(event)s&thread_id=%(thread_id)s&_username=%(username)s" % {
        "username": admin_username,
        "thread_id": options.thread_id,
        "event": options.event,
    }

    signature = utils.compute_signature("POST", path, "", admin_password)

    url = "http://127.0.0.1:%(port)s" + path + "&_signature=" + signature
    url = url % {"port": settings.PORT}

    try:
        response = urllib.urlopen(url, data="")
        response = json.load(response)
        if response.get("error"):
            raise Exception(response["error"])

        logging.debug("event successfully relayed")

    except Exception as e:
        logging.error("failed to relay event: %s" % e)

    logging.debug("bye!")
Beispiel #16
0
def main(parser, args):
    import meyectl
    
    options = parse_options(parser, args)
    
    meyectl.configure_logging('relayevent', options.log_to_file)
    meyectl.configure_tornado()

    logging.debug('hello!')
    logging.debug('event = %s' % options.event)
    logging.debug('thread_id = %s' % options.thread_id)
    
    admin_username, admin_password = get_admin_credentials()

    uri = '/_relay_event/?event=%(event)s&thread_id=%(thread_id)s&_username=%(username)s' % {
            'username': admin_username,
            'thread_id': options.thread_id,
            'event': options.event}
    
    signature = utils.compute_signature('POST', uri, '', admin_password)
    
    url = 'http://127.0.0.1:%(port)s' + uri + '&_signature=' + signature
    url = url % {'port': settings.PORT}
    
    try:
        response = urllib.urlopen(url, data='')
        response = json.load(response)
        if response.get('error'):
            raise Exception(response['error'])
        
        logging.debug('event successfully relayed')
    
    except Exception as e:
        logging.error('failed to relay event: %s' % e)

    logging.debug('bye!')
def main(parser, args):
    import meyectl

    # the motion daemon overrides SIGCHLD,
    # so we must restore it here,
    # or otherwise media listing won't work
    signal.signal(signal.SIGCHLD, signal.SIG_DFL)

    if len(args) == 12:
        # backwards compatibility with older configs lacking "from" field
        _from = 'motionEye on %s <%s>' % (socket.gethostname(),
                                          args[7].split(',')[0])
        args = args[:7] + [_from] + args[7:]

    if not args[7]:
        args[7] = 'motionEye on %s <%s>' % (socket.gethostname(),
                                            args[8].split(',')[0])

    options = parse_options(parser, args)

    meyectl.configure_logging('sendmail', options.log_to_file)

    logging.debug('hello!')

    options.port = int(options.port)
    options.tls = options.tls.lower() == 'true'
    options.timespan = int(options.timespan)
    message = messages.get(options.msg_id)
    subject = subjects.get(options.msg_id)
    options.moment = datetime.datetime.strptime(options.moment,
                                                '%Y-%m-%dT%H:%M:%S')
    options.password = options.password.replace('\\;',
                                                ';')  # unescape password

    # do not wait too long for media list,
    # email notifications are critical
    settings.LIST_MEDIA_TIMEOUT = settings.LIST_MEDIA_TIMEOUT_EMAIL

    camera_id = motionctl.thread_id_to_camera_id(options.thread_id)
    _from = getattr(options, 'from')

    logging.debug('server = %s' % options.server)
    logging.debug('port = %s' % options.port)
    logging.debug('account = %s' % options.account)
    logging.debug('password = ******')
    logging.debug('server = %s' % options.server)
    logging.debug('tls = %s' % str(options.tls).lower())
    logging.debug('from = %s' % _from)
    logging.debug('to = %s' % options.to)
    logging.debug('msg_id = %s' % options.msg_id)
    logging.debug('thread_id = %s' % options.thread_id)
    logging.debug('camera_id = %s' % camera_id)
    logging.debug('moment = %s' % options.moment.strftime('%Y-%m-%d %H:%M:%S'))
    logging.debug('smtp timeout = %d' % settings.SMTP_TIMEOUT)
    logging.debug('timespan = %d' % options.timespan)

    to = [t.strip() for t in re.split('[,;| ]', options.to)]
    to = [t for t in to if t]

    def on_message(subject, message, files):
        try:
            logging.info('sending email')
            send_mail(options.server, options.port, options.account,
                      options.password, options.tls, _from, to, subject,
                      message, files or [])
            logging.info('email sent')

        except Exception as e:
            logging.error('failed to send mail: %s' % e, exc_info=True)

        logging.debug('bye!')

    make_message(subject, message, camera_id, options.moment, options.timespan,
                 on_message)
Beispiel #18
0
def main(parser, args):
    import meyectl
    
    # the motion daemon overrides SIGCHLD,
    # so we must restore it here,
    # or otherwise media listing won't work
    signal.signal(signal.SIGCHLD,signal.SIG_DFL)

    if len(args) == 12:
        # backwards compatibility with older configs lacking "from" field
        _from = 'motionEye on %s <%s>' % (socket.gethostname(), args[7].split(',')[0])
        args = args[:7] + [_from] + args[7:]
    
    if not args[7]:
        args[7] = 'motionEye on %s <%s>' % (socket.gethostname(), args[8].split(',')[0])

    options = parse_options(parser, args)
    
    meyectl.configure_logging('sendmail', options.log_to_file)

    logging.debug('hello!')

    options.port = int(options.port) 
    options.tls = options.tls.lower() == 'true'
    options.timespan = int(options.timespan)
    message = messages.get(options.msg_id)
    subject = subjects.get(options.msg_id)
    options.moment = datetime.datetime.strptime(options.moment, '%Y-%m-%dT%H:%M:%S')
    options.password = options.password.replace('\\;', ';') # unescape password
    
    # do not wait too long for media list,
    # email notifications are critical
    settings.LIST_MEDIA_TIMEOUT = settings.LIST_MEDIA_TIMEOUT_EMAIL
    
    camera_id = motionctl.thread_id_to_camera_id(options.thread_id)
    _from = getattr(options, 'from')

    logging.debug('server = %s' % options.server)
    logging.debug('port = %s' % options.port)
    logging.debug('account = %s' % options.account)
    logging.debug('password = ******')
    logging.debug('server = %s' % options.server)
    logging.debug('tls = %s' % str(options.tls).lower())
    logging.debug('from = %s' % _from)
    logging.debug('to = %s' % options.to)
    logging.debug('msg_id = %s' % options.msg_id)
    logging.debug('thread_id = %s' % options.thread_id)
    logging.debug('camera_id = %s' % camera_id)
    logging.debug('moment = %s' % options.moment.strftime('%Y-%m-%d %H:%M:%S'))
    logging.debug('smtp timeout = %d' % settings.SMTP_TIMEOUT)
    logging.debug('timespan = %d' % options.timespan)
    
    to = [t.strip() for t in re.split('[,;| ]', options.to)]
    to = [t for t in to if t]

    def on_message(subject, message, files):
        try:
            send_mail(options.server, options.port, options.account, options.password,
                    options.tls, _from, to, subject, message, files or [])
            logging.info('email sent')

        except Exception as e:
            logging.error('failed to send mail: %s' % e, exc_info=True)

        logging.debug('bye!')
    
    make_message(subject, message, camera_id, options.moment, options.timespan, on_message)
Beispiel #19
0
def main(parser, args):
    import meyectl

    # the motion daemon overrides SIGCHLD,
    # so we must restore it here,
    # or otherwise media listing won't work
    signal.signal(signal.SIGCHLD, signal.SIG_DFL)

    options = parse_options(parser, args)

    meyectl.configure_logging('sendmail', options.log_to_file)

    logging.debug('hello!')

    options.port = int(options.port)
    options.tls = options.tls.lower() == 'true'
    options.timespan = int(options.timespan)
    message = messages.get(options.msg_id)
    subject = subjects.get(options.msg_id)
    options.moment = datetime.datetime.strptime(options.moment,
                                                '%Y-%m-%dT%H:%M:%S')
    options.password = options.password.replace('\\;',
                                                ';')  # unescape password

    # do not wait too long for media list,
    # email notifications are critical
    settings.LIST_MEDIA_TIMEOUT = 10

    camera_id = motionctl.thread_id_to_camera_id(options.thread_id)

    logging.debug('server = %s' % options.server)
    logging.debug('port = %s' % options.port)
    logging.debug('account = %s' % options.account)
    logging.debug('password = ******')
    logging.debug('server = %s' % options.server)
    logging.debug('tls = %s' % str(options.tls).lower())
    logging.debug('to = %s' % options.to)
    logging.debug('msg_id = %s' % options.msg_id)
    logging.debug('thread_id = %s' % options.thread_id)
    logging.debug('camera_id = %s' % camera_id)
    logging.debug('moment = %s' % options.moment.strftime('%Y-%m-%d %H:%M:%S'))
    logging.debug('smtp timeout = %d' % settings.SMTP_TIMEOUT)
    logging.debug('timespan = %d' % options.timespan)

    to = [t.strip() for t in re.split('[,;| ]', options.to)]
    to = [t for t in to if t]

    def on_message(subject, message, files):
        try:
            send_mail(options.server, options.port, options.account,
                      options.password, options.tls, to, subject, message,
                      files or [])
            logging.info('email sent')

        except Exception as e:
            logging.error('failed to send mail: %s' % e, exc_info=True)

        logging.debug('bye!')

    make_message(subject, message, camera_id, options.moment, options.timespan,
                 on_message)