From d4b8a1ccacda08c29ad93cdb344c6fc1debcac30 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 5 Mar 2020 10:22:52 +0100 Subject: db/utils: move formataddr to helper It has no relation to database, so helper seems like a better place for it. As there is nothing left in db/utils, it is removed. --- alot/commands/thread.py | 2 +- alot/completion/abooks.py | 2 +- alot/completion/accounts.py | 2 +- alot/db/message.py | 1 - alot/db/utils.py | 28 ---------------------------- alot/helper.py | 13 +++++++++++++ 6 files changed, 16 insertions(+), 32 deletions(-) delete mode 100644 alot/db/utils.py (limited to 'alot') diff --git a/alot/commands/thread.py b/alot/commands/thread.py index c5e2747e..83aef9a0 100644 --- a/alot/commands/thread.py +++ b/alot/commands/thread.py @@ -26,11 +26,11 @@ from .common import RetagPromptCommand from .envelope import SendCommand from ..completion.contacts import ContactsCompleter from ..completion.path import PathCompleter -from ..db.utils import formataddr from ..db.envelope import Envelope from ..db.attachment import Attachment from ..db.errors import DatabaseROError from ..settings.const import settings +from ..helper import formataddr from ..helper import parse_mailcap_nametemplate from ..helper import split_commandstring from ..utils import argparse as cargparse diff --git a/alot/completion/abooks.py b/alot/completion/abooks.py index bc2fa20b..c5bfe3e8 100644 --- a/alot/completion/abooks.py +++ b/alot/completion/abooks.py @@ -4,7 +4,7 @@ from .completer import Completer from ..addressbook import AddressbookError -from ..db.utils import formataddr +from ..helper import formataddr from ..errors import CompletionError diff --git a/alot/completion/accounts.py b/alot/completion/accounts.py index 20dbcfa6..3250a7c9 100644 --- a/alot/completion/accounts.py +++ b/alot/completion/accounts.py @@ -3,7 +3,7 @@ # For further details see the COPYING file from alot.settings.const import settings -from alot.db.utils import formataddr +from alot.helper import formataddr from .stringlist import StringlistCompleter diff --git a/alot/db/message.py b/alot/db/message.py index 6523f18b..7263c6fe 100644 --- a/alot/db/message.py +++ b/alot/db/message.py @@ -11,7 +11,6 @@ from datetime import datetime from notmuch import NullPointerError -from . import utils from .attachment import Attachment from .. import crypto from .. import helper diff --git a/alot/db/utils.py b/alot/db/utils.py deleted file mode 100644 index 99684afd..00000000 --- a/alot/db/utils.py +++ /dev/null @@ -1,28 +0,0 @@ -# encoding=utf-8 -# Copyright (C) 2011-2012 Patrick Totzke -# Copyright © 2017 Dylan Baker -# This file is released under the GNU GPL, version 3 or a later revision. -# For further details see the COPYING file -import os -import email -import email.charset as charset -import email.policy -import email.utils -import logging - -from ..settings.const import settings - -charset.add_charset('utf-8', charset.QP, charset.QP, 'utf-8') - -def formataddr(pair): - """ this is the inverse of email.utils.parseaddr: - other than email.utils.formataddr, this - - *will not* re-encode unicode strings, and - - *will* re-introduce quotes around real names containing commas - """ - name, address = pair - if not name: - return address - elif ',' in name: - name = "\"" + name + "\"" - return "{0} <{1}>".format(name, address) diff --git a/alot/helper.py b/alot/helper.py index aab3242e..1d541d76 100644 --- a/alot/helper.py +++ b/alot/helper.py @@ -602,3 +602,16 @@ def get_xdg_env(env_name, fallback): """ Used for XDG_* env variables to return fallback if unset *or* empty """ env = os.environ.get(env_name) return env if env else fallback + +def formataddr(pair): + """ this is the inverse of email.utils.parseaddr: + other than email.utils.formataddr, this + - *will not* re-encode unicode strings, and + - *will* re-introduce quotes around real names containing commas + """ + name, address = pair + if not name: + return address + elif ',' in name: + name = "\"" + name + "\"" + return "{0} <{1}>".format(name, address) -- cgit v1.2.3