def process(self, data): mailpath, filename = self.get_paths(data) ## First check integrity error = None if not access(mailpath, F_OK | R_OK | W_OK): error = 'No access to mailpath' try: makedirs(mailpath, 0700) error = None except: t, val, tb = exc_info() del tb error = '%s: %s' % (t, val) self.LOG(E_ERR, 'Filesystem Backend: Cannot create storage directory: ' + str(val)) if error is not None: return 0, 443, error if self.compression is not None: name = '%d-%d.eml' % (data['year'], data['pid']) comp = CompressedFile(compressor=self.compression[0], ratio=self.compression[1], name=name) comp.write(data['mail']) data['mail'] = comp.getdata() comp.close() try: fd = open(filename, 'wb') fd.write(data['mail']) fd.flush() fd.close() self.LOG(E_TRACE, 'Filesystem Backend: wrote ' + filename) return BACKEND_OK except: t, val, tb = exc_info() del tb self.LOG(E_ERR, 'Filesystem Backend: Cannot write mail file: ' + str(val)) return 0, 443, '%s: %s' % (t, val)
def process(self, data): mailpath, filename = self.get_paths(data) try: stat(self.image) except: self.LOG(E_ALWAYS, self._prefix + 'Image not present, creating it') if not self.create(): self.LOG(E_ERR, self._prefix + 'Cannot create Image file') return 0, 443, 'Internal Error (Image creation failed)' if not self.initImage(): self.LOG(E_ERR, self._prefix + 'Cannot init Image') return 0, 443, 'Internal Error (Cannot init Image)' error = None if not access(mailpath, F_OK | R_OK | W_OK): error = 'No access to mailpath' try: makedirs(mailpath, 0700) error = None except: t, val, tb = exc_info() del tb error = '%s: %s' % (t, val) self.LOG(E_ERR, self._prefix + 'Cannot create storage directory: %s' % str(val)) if error is not None: return 0, 443, error if self.compression is not None: name = '%d-%d.eml' % (data['year'], data['pid']) comp = CompressedFile(compressor=self.compression[0], ratio=self.compression[1], name=name) comp.write(data['mail']) data['mail'] = comp.getdata() comp.close() error_no = 0 try: fd = open(filename, 'wb') fd.write(data['mail']) except: t, val, tb = exc_info() error_no = val.errno try: fd.close() except: pass ## An error occurred unlink file and check if the volume is full if error_no: try: unlink(filename) except: pass if error_no == ENOSPC: if not self.recycle(): self.LOG(E_ERR, self._prefix + 'Error recycling Image') return 0, 443, 'Internal Error (Recycling failed)' self.LOG(E_ALWAYS, self._prefix + 'Recycled Image File, write postponed') return 0, 443, 'Recycling volume' else: self.LOG(E_ERR, self._prefix + 'Cannot write mail file: %s' % str(val)) return 0, 443, '%s: %s' % (t, val) self.LOG(E_TRACE, self._prefix + 'wrote %s' % filename) res, data, msg = self.do_query(update_query % data, fetch=False, autorecon=True) if not res: try: unlink(filename) except: pass self.LOG(E_ERR, self._prefix + 'Error updating mail entry [%s], removing file from Image' % msg) return 0, 443, 'Internal Error while updating mail entry' return BACKEND_OK