2014-01-14 22:20:12 -08:00
|
|
|
import sys
|
|
|
|
|
|
2014-04-25 16:37:51 -07:00
|
|
|
from .base import EmailTransport
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class GenericFileMailbox(EmailTransport):
|
2012-06-30 22:30:13 -07:00
|
|
|
_variant = None
|
|
|
|
|
_path = None
|
|
|
|
|
|
|
|
|
|
def __init__(self, path):
|
2019-10-15 05:31:13 +02:00
|
|
|
super().__init__()
|
|
|
|
|
self._path = path
|
2012-06-30 22:30:13 -07:00
|
|
|
|
|
|
|
|
def get_instance(self):
|
|
|
|
|
return self._variant(self._path)
|
|
|
|
|
|
2015-07-07 22:22:15 -07:00
|
|
|
def get_message(self, condition=None):
|
2012-06-30 22:30:13 -07:00
|
|
|
repository = self.get_instance()
|
|
|
|
|
repository.lock()
|
|
|
|
|
for key, message in repository.items():
|
2015-07-07 22:22:15 -07:00
|
|
|
if condition and not condition(message):
|
|
|
|
|
continue
|
2012-06-30 22:30:13 -07:00
|
|
|
repository.remove(key)
|
|
|
|
|
yield message
|
2016-12-26 01:12:14 +01:00
|
|
|
repository.flush()
|
2012-06-30 22:30:13 -07:00
|
|
|
repository.unlock()
|