2014-01-14 22:20:12 -08:00
|
|
|
import sys
|
2015-07-21 11:50:15 -04:00
|
|
|
import six
|
2014-01-14 22:20:12 -08:00
|
|
|
|
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):
|
|
|
|
|
super(GenericFileMailbox, self).__init__()
|
2015-07-21 11:50:15 -04:00
|
|
|
if six.PY2:
|
|
|
|
|
self._path = path.encode(
|
|
|
|
|
sys.getfilesystemencoding()
|
|
|
|
|
)
|
|
|
|
|
else:
|
|
|
|
|
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
|
|
|
|
|
repository.unlock()
|