summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--alot/commands/thread.py35
-rw-r--r--alot/db/message.py11
2 files changed, 27 insertions, 19 deletions
diff --git a/alot/commands/thread.py b/alot/commands/thread.py
index 83aef9a0..f34a371d 100644
--- a/alot/commands/thread.py
+++ b/alot/commands/thread.py
@@ -682,45 +682,48 @@ class PipeCommand(Command):
return
# prepare message sources
- pipestrings = []
- separator = '\n\n'
+ pipe_data = []
logging.debug('PIPETO format')
logging.debug(self.output_format)
if self.output_format == 'id':
- pipestrings = [e.id for e in to_print]
- separator = '\n'
+ pipe_data = [e.id.encode('utf-8') for e in to_print]
+ separator = b'\n'
elif self.output_format == 'filepath':
- pipestrings = [e.filename for e in to_print]
- separator = '\n'
+ pipe_data = [e.filename for e in to_print]
+ separator = b'\n'
else:
+ separator = b'\n\n'
for msg in to_print:
- mail = msg.get_email()
- if self.add_tags:
- mail.add_header('Tags', ', '.join(msg.get_tags()))
if self.output_format == 'raw':
- pipestrings.append(mail.as_string())
+ msg_data = msg.as_bytes()
elif self.output_format == 'decoded':
headertext = '\n'.join([key + ': ' + val for key, val in msg.headers.items()])
bodytext = msg.get_body_text()
msgtext = '%s\n\n%s' % (headertext, bodytext)
- pipestrings.append(msgtext)
+
+ msg_data = msgtext.encode('utf-8')
+
+ if self.add_tags:
+ tags = 'Tags: ' + ','.join(msg.get_tags()) + '\n'
+ msg_data = tags.encode('utf-8') + msg_data
+
+ pipe_data.append(msg_data)
if not self.separately:
- pipestrings = [separator.join(pipestrings)]
+ pipe_data = [separator.join(pipe_data)]
if self.shell:
self.cmd = [' '.join(self.cmd)]
# do the monkey
- for mail in pipestrings:
- encoded_mail = mail.encode(urwid.util.detected_encoding)
+ for d in pipe_data:
if self.background:
logging.debug('call in background: %s', self.cmd)
proc = subprocess.Popen(self.cmd,
shell=True, stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
- out, err = proc.communicate(encoded_mail)
+ out, err = proc.communicate(d)
if self.notify_stdout:
ui.notify(out, block = True)
else:
@@ -732,7 +735,7 @@ class PipeCommand(Command):
stdin=subprocess.PIPE,
# stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
- out, err = proc.communicate(encoded_mail)
+ out, err = proc.communicate(d)
if err:
ui.notify(err, priority='error')
return
diff --git a/alot/db/message.py b/alot/db/message.py
index f9092e41..90bba469 100644
--- a/alot/db/message.py
+++ b/alot/db/message.py
@@ -443,7 +443,12 @@ class Message:
filenames = []
for f in msg.get_filenames():
- filenames.append(f[:])
+ # FIXME these should be returned as bytes, but the notmuch bindings
+ # decode them
+ # this should be resolved by switching to the newer notmuch2
+ # bindings
+ # for now, just re-encode them in utf-8
+ filenames.append(f.encode('utf-8'))
if len(filenames) == 0:
raise ValueError('No filenames for a message returned')
self.filenames = filenames
@@ -493,8 +498,8 @@ class Message:
return self.filenames[0]
def _load_email(self, session_keys):
- warning = "Subject: Caution!\n"\
- "Message file is no longer accessible:\n%s" % self.filename
+ warning = b"Subject: Caution!\n"\
+ b"Message file is no longer accessible:\n%s" % self.filename
try:
with open(self.filename, 'rb') as f:
mail = _decrypted_message_from_bytes(f.read(), session_keys)