Ejemplo n.º 1
0
def receive_fax():
    parameters = [arg.rstrip() for arg in argv]
    try:
        scriptname = parameters[0]
        filename = parameters[1]
        device = parameters[2]
        commid = parameters[3]
        reason = parameters[4]
        cid = parameters[5]
        mystery2 = parameters[6]
        msn = parameters[7]
    except IndexError:
        pass
    logging.info("Processing received fax %s" % commid)
    logging.debug(
        "Fax %s in file %s, received on device %s MSN %s, "
        'reason "%s", id %s' % (commid, filename, device, msn, reason, cid)
    )
    fullfname = settings.FAX_SPOOL_DIR + "/%s" % filename
    fax = Fax()
    fax.received_on = datetime.fromtimestamp(os.path.getmtime(fullfname))
    fax.filename = filename
    fax.device = device
    fax.comm_id = commid
    fax.msn = msn
    fax.caller_id = cid
    fax.msn = mystery2
    fax.status = 1  # Success
    fax.reason = reason
    try:
        fax.update_from_tiff()
    except ValueError, e:
        if not fax.reason == "":
            # There was an error
            fax.error = True
            fax.status = 2  # Error
            logging.info("Fax %s has an error; reason: %s" % fax.reason)
        else:
            raise e
Ejemplo n.º 2
0
    def handle(self, *args, **options):

        if len(args) < 4:
            raise AttributeError

        qfile, devid, commid, msg = map(str.rstrip, args[:4])
        callid = map(str.strip, args[4:])

        logger.info('Processing received fax %s', commid)
        logger.debug('Fax %s in file %s, received on device %s, message: %s', commid, qfile, devid, msg)

        filename = settings.FAX_SPOOL_DIR + '/' + qfile

        fax = Fax()
        fax.received_on = datetime.fromtimestamp(os.path.getmtime(filename))
        fax.filename = qfile
        fax.device = devid
        fax.comm_id = commid
        fax.reason = msg
        fax.status = 1  # Success
        # TODO improve caller_id
        fax.caller_id = str(callid)

        if os.path.isfile(filename):
            fax.update_from_tiff()
        else:
            fax.error = True
            fax.status = 2  # Error
            logging.info("Fax %s has an error; reason: %s", commid, msg)

        fax.update_from_logfile()
        if fax.station_id == fax.caller_id or fax.station_id == '-':
            fax.station_id = None
        fax.set_sender()
        fax.save()
        FaxImage(fax).cache_thumbnails()