Commit 3697d672 authored by Julien Cristau's avatar Julien Cristau
Browse files

[cwemail] deal with unseekable files (closes #9363488)

The mailbox module wants to seek into the file to build its toc, so give
it a BytesIO if our input stream isn't seekable.
parent 5c0b31f6db4f
......@@ -134,7 +134,7 @@ def main():
'endpoint', metavar='endpoint', type=str,
help='cwclientlib endpoint of the cubicweb instance')
parser.add_argument(
'mbox', metavar='mailbox', type=argparse.FileType('r'),
'mbox', metavar='mailbox', type=argparse.FileType('rb'),
nargs='+', help='mbox files to import (- for stdin)')
args = parser.parse_args()
......@@ -142,6 +142,13 @@ def main():
importer = Importer(proxy)
for f in args.mbox:
try:
f.seek(0)
except IOError:
buf = BytesIO()
buf.writelines(f)
buf.seek(0)
f = buf
importer.import_mbox_stream(f)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment