Print username instead of accountname when asking for password

When asking for a password interactively, the username is never
displayed which may hide problems (typos on the configuration, or
issues on offlineimap parsing of the config file).  The hostname,
port, and account name are already displayed when establishing the
connection.  When asking for password, the account name is displayed
again.  Change it to display the username.

Github-ref: https://github.com/OfflineIMAP/offlineimap/issues/558
Signed-off-by: David Miguel Susano Pinto <carandraug+dev@gmail.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Carnë Draug 2018-06-13 13:05:13 +01:00 committed by Nicolas Sebrecht
parent 11313a9b9c
commit 5f9474e10d
5 changed files with 11 additions and 12 deletions

View File

@ -175,8 +175,7 @@ class IMAPServer(object):
# get 1) configured password first 2) fall back to asking via UI # get 1) configured password first 2) fall back to asking via UI
self.password = self.repos.getpassword() or \ self.password = self.repos.getpassword() or \
self.ui.getpass(self.repos.getname(), self.config, self.ui.getpass(self.username, self.config, self.passworderror)
self.passworderror)
self.passworderror = None self.passworderror = None
return self.password return self.password

View File

@ -549,7 +549,7 @@ class Blinkenlights(UIBase, CursesUtil):
def mainException(self): def mainException(self):
UIBase.mainException(self) UIBase.mainException(self)
def getpass(self, accountname, config, errmsg=None): def getpass(self, username, config, errmsg=None):
# disable the hotkeys inputhandler # disable the hotkeys inputhandler
self.inputhandler.input_acquire() self.inputhandler.input_acquire()
@ -558,8 +558,8 @@ class Blinkenlights(UIBase, CursesUtil):
try: try:
#s.gettf().setcolor('white') #s.gettf().setcolor('white')
self.warn(" *** Input Required") self.warn(" *** Input Required")
self.warn(" *** Please enter password for account %s: " % \ self.warn(" *** Please enter password for user '%s': " % \
accountname) username)
self.logwin.refresh() self.logwin.refresh()
password = self.logwin.getstr() password = self.logwin.getstr()
finally: finally:

View File

@ -182,15 +182,15 @@ class MachineUI(UIBase):
return 0 return 0
def getpass(s, accountname, config, errmsg=None): def getpass(s, username, config, errmsg=None):
if errmsg: if errmsg:
s._printData(s.logger.warning, s._printData(s.logger.warning,
'getpasserror', "%s\n%s"% (accountname, errmsg), 'getpasserror', "%s\n%s"% (username, errmsg),
False) False)
s._log_con_handler.acquire() # lock the console output s._log_con_handler.acquire() # lock the console output
try: try:
s._printData(s.logger.info, 'getpass', accountname) s._printData(s.logger.info, 'getpass', username)
return (sys.stdin.readline()[:-1]) return (sys.stdin.readline()[:-1])
finally: finally:
s._log_con_handler.release() s._log_con_handler.release()

View File

@ -76,14 +76,14 @@ class TTYUI(UIBase):
return sys.stdout.isatty() and sys.stdin.isatty() return sys.stdout.isatty() and sys.stdin.isatty()
def getpass(self, accountname, config, errmsg=None): def getpass(self, username, config, errmsg=None):
"""TTYUI backend is capable of querying the password.""" """TTYUI backend is capable of querying the password."""
if errmsg: if errmsg:
self.warn("%s: %s"% (accountname, errmsg)) self.warn("%s: %s"% (username, errmsg))
self._log_con_handler.acquire() # lock the console output self._log_con_handler.acquire() # lock the console output
try: try:
return getpass("Enter password for account '%s': " % accountname) return getpass("Enter password for user '%s': " % username)
finally: finally:
self._log_con_handler.release() self._log_con_handler.release()

View File

@ -257,7 +257,7 @@ class UIBase(object):
################################################## INPUT ################################################## INPUT
def getpass(self, accountname, config, errmsg = None): def getpass(self, username, config, errmsg = None):
raise NotImplementedError("Prompting for a password is not supported" raise NotImplementedError("Prompting for a password is not supported"
" in this UI backend.") " in this UI backend.")