Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When piping imapcli output, an exception is raised if emails contain … #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/multimailboxsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def main():

if len(mail_set) > 0:
sys.stdout.write(u'{} Directory\n'.format(
directory_status['directory']))
directory_status['directory']).encode('UTF-8'))

for mail_info in search.fetch_mails_info(imap_account,
mail_set=mail_set):
Expand All @@ -64,7 +64,7 @@ def main():
sys.stdout.write(format_string.format(
mail_info['uid'],
mail_info['from'],
mail_info['subject']))
mail_info['subject']).encode('UTF-8'))
imap_cli.disconnect(imap_account)
except KeyboardInterrupt:
log.info('Interrupt by user, exiting')
Expand Down
4 changes: 2 additions & 2 deletions examples/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def main():
for directory_status in sorted(imap_cli.status(imap_account),
key=lambda obj: obj['directory']):
if int(directory_status['unseen']) > 0:
sys.stdout.write(directory_status['directory'])
sys.stdout.write(directory_status['directory'].encode('UTF-8'))
sys.stdout.write('\n')

imap_cli.change_dir(imap_account,
Expand All @@ -62,7 +62,7 @@ def main():
sys.stdout.write(format_string.format(
mail_info['uid'],
mail_info['from'],
mail_info['subject']))
mail_info['subject']).encode('UTF-8'))
imap_cli.disconnect(imap_account)
except KeyboardInterrupt:
log.info('Interrupt by user, exiting')
Expand Down
4 changes: 2 additions & 2 deletions imap_cli/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def main():
if len(args['<mail_uid>']) == 0:
args['<mail_uid>'] = sys.stdin.read().strip().split()
if len(args['<mail_uid>']) == 0:
sys.stderr.write('\n'.join(__doc__.split('\n')[2:]))
sys.stderr.write('\n'.join(__doc__.split('\n')[2:]).encode('UTF-8'))
return 1

conf = config.new_context_from_file(args['--config-file'], section='imap')
Expand All @@ -220,7 +220,7 @@ def main():
return 1

for fetched_mail in fetched_mails:
sys.stdout.write(display(fetched_mail))
sys.stdout.write(display(fetched_mail).encode('UTF-8'))

imap_cli.disconnect(imap_account)
except KeyboardInterrupt:
Expand Down
4 changes: 2 additions & 2 deletions imap_cli/list_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def main():
for mail_info in search.fetch_mails_info(imap_account,
limit=limit):
sys.stdout.write(
display_conf['format_list'].format(**mail_info))
display_conf['format_list'].format(**mail_info).encode('UTF-8'))
sys.stdout.write('\n')
else:
threads = search.fetch_threads(imap_account, limit=limit)
Expand All @@ -88,7 +88,7 @@ def main():
imap_account,
mail_tree,
format_thread=display_conf['format_thread']):
sys.stdout.write(output)
sys.stdout.write(output.encode('UTF-8'))
sys.stdout.write('\n')
imap_cli.disconnect(imap_account)
except KeyboardInterrupt:
Expand Down
10 changes: 5 additions & 5 deletions imap_cli/scripts/imap_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def do_list(self, arg):
u'UID : {:<10} From : {:<40.40} Subject : {:.50}\n'.format(
mail_info['uid'],
mail_info['from'],
mail_info['subject']))
mail_info['subject']).encode('UTF-8'))

def do_mv(self, arg):
'''Move mail from one mailbox to another.'''
Expand Down Expand Up @@ -167,7 +167,7 @@ def do_read(self, arg):

temp_file.close()
else:
sys.stdout.write(fetch.display(fetched_mail))
sys.stdout.write(fetch.display(fetched_mail).encode('UTF-8'))

def do_search(self, arg):
'''Search mail.'''
Expand Down Expand Up @@ -217,7 +217,7 @@ def do_search(self, arg):
u'UID : {:<10} From : {:<40.40} Subject : {:.50}\n'.format(
mail_info['uid'],
mail_info['from'],
mail_info['subject']))
mail_info['subject']).encode('UTF-8'))

def do_status(self, arg):
'Print status of all IMAP folder in this account'
Expand All @@ -229,7 +229,7 @@ def do_status(self, arg):
directory_status['directory'],
directory_status['unseen'],
directory_status['recent'],
directory_status['count']))
directory_status['count']).encode('UTF-8'))

def do_unseen(self, arg):
'''List Unseen mail (equivalent to "search -t unseen").'''
Expand All @@ -245,7 +245,7 @@ def do_unseen(self, arg):
u'UID : {:<10} From : {:<40.40} Subject : {:.50}\n'.format(
mail_info['uid'],
mail_info['from'],
mail_info['subject']))
mail_info['subject']).encode('UTF-8'))

def emptyline(self):
pass
Expand Down
4 changes: 2 additions & 2 deletions imap_cli/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def main():
for mail_info in fetch_mails_info(imap_account,
limit=limit, mail_set=mail_set):
sys.stdout.write(
display_conf['format_list'].format(**mail_info))
display_conf['format_list'].format(**mail_info).encode('UTF-8'))
sys.stdout.write('\n')
else:
threads = fetch_threads(imap_account, limit=limit,
Expand All @@ -488,7 +488,7 @@ def main():
for output in display_mail_tree(
imap_account, mail_tree,
format_thread=display_conf['format_thread']):
sys.stdout.write(output)
sys.stdout.write(output.encode('UTF-8'))
sys.stdout.write('\n')

imap_cli.disconnect(imap_account)
Expand Down
2 changes: 1 addition & 1 deletion imap_cli/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def main():
for directory_status in sorted(imap_cli.status(imap_account),
key=lambda obj: obj['directory']):
sys.stdout.write(
display_conf['format_status'].format(**directory_status))
display_conf['format_status'].format(**directory_status).encode('UTF-8'))
sys.stdout.write('\n')
except KeyboardInterrupt:
log.info('Interrupt by user, exiting')
Expand Down