Esempio n. 1
0
    def cleanup(self):
        if not self.exists():
            return

        lifetimesecs = Util.seconds(Defaults.PENDING_LIFETIME)
        cwd = os.getcwd()
        os.chdir(Defaults.PENDING_DIR)
        msgs = glob.glob('*.*.msg')
        os.chdir(cwd)

        for msg in msgs:
            now = '%d' % time.time()
            min_time = int(now) - int(lifetimesecs)
            msg_time = int(msg.split('.')[0])
            if msg_time > min_time:
                # skip this message
                continue
            # delete this message
            fpath = os.path.join(Defaults.PENDING_DIR, msg)
            if Defaults.PENDING_DELETE_APPEND:
                try:
                    msgobj = Util.msg_from_file(open(fpath, 'r'))
                except IOError:
                    # in case of concurrent cleanups
                    pass
                else:
                    rp = parseaddr(msgobj.get('return-path'))[1]
                    Util.append_to_file(rp, Defaults.PENDING_DELETE_APPEND)
            try:
                os.unlink(fpath)
            except OSError:
                # in case of concurrent cleanups
                pass
Esempio n. 2
0
    def cleanup(self):
        if not self.exists():
            return

        lifetimesecs = Util.seconds(Defaults.PENDING_LIFETIME)
        cwd = os.getcwd()
        os.chdir(Defaults.PENDING_DIR)
        msgs = glob.glob('*.*.msg')
        os.chdir(cwd)

        for msg in msgs:
            now = '%d' % time.time()
            min_time = int(now) - int(lifetimesecs)
            msg_time = int(msg.split('.')[0])
            if msg_time > min_time:
                # skip this message
                continue
            # delete this message
            fpath = os.path.join(Defaults.PENDING_DIR, msg)
            if Defaults.PENDING_DELETE_APPEND:
                try:
                    msgobj = Util.msg_from_file(open(fpath, 'r'))
                except IOError:
                    # in case of concurrent cleanups
                    pass
                else:
                    rp = parseaddr(msgobj.get('return-path'))[1]
                    Util.append_to_file(rp, Defaults.PENDING_DELETE_APPEND)
            try:
                os.unlink(fpath)
            except OSError:
                # in case of concurrent cleanups
                pass
Esempio n. 3
0
 def fetch_message(self, mailid, fullParse=False):
     msgs = (glob(os.path.join(Defaults.PENDING_DIR, 'new/')
                  + '1*.[0-9]*.*')) + \
                  (glob(os.path.join(Defaults.PENDING_DIR, 'cur/')
                        + '1*.[0-9]*.*'))
     for m in msgs:
         if mailid in m:
             msg = Util.msg_from_file(file(m, 'r'),fullParse=fullParse)
             return msg
     else:
         # couldn't find message, defer and retry until we find it
         raise IOError, "couldn't locate %s, will retry" % m
Esempio n. 4
0
 def fetch_message(self, mailid, fullParse=False):
     fpath = os.path.join(Defaults.PENDING_DIR, mailid + '.msg')
     msg = Util.msg_from_file(file(fpath, 'r'), fullParse=fullParse)
     return msg
Esempio n. 5
0
 def fetch_message(self, mailid, fullParse=False):
     fpath = os.path.join(Defaults.PENDING_DIR, mailid + '.msg')
     msg = Util.msg_from_file(file(fpath, 'r'),fullParse=fullParse)
     return msg