[patch] Use /etc/mailname if available

John A Meinel john at arbash-meinel.com
Sun Dec 18 14:01:30 GMT 2005


Jeff Garrett wrote:
> Bzr currently attempts to guess the name and e-mail address of the user
> (if not configured).  Unfortunately, the e-mail address has only the
> hostname, not the FQDN of the machine (cf. the thread "Slow Startup?"
> from April 14) because OS/X does not have a sane default DNS resolution
> setup.  As such, it can hardly ever give a valid e-mail address.
> 
> In many cases, /etc/mailname will contain the correct domain name for
> e-mail addresses.  Hopefully, this should obviate the configuration step
> for some users.  Attached is a short patch to this effect.
> 
> -Jeff
> JID: jeff at jgarrett.org
> 

Is there a way to check if socket.gethostname() returns something
reasonable? I know I've never heard of /etc/mailname before. I couldn't
find it in man pages, though I believe I understand how it should work.

I can understand trusting /etc/mailname before gethostname(), since if
someone sets it up, I assume that means they intended it to be the
official mail address.

I would like to check that mailname is not empty, though.
Something more like:

mailname = None
try:
  mailname = open(u'/etc/mailname').read().strip()
except IOError:
  pass

if not mailname:
  mailname = socket.gethostname()

if not mailname:
  ...

return realname, (username + '@' + mailname)

John
=:->

> 
> ------------------------------------------------------------------------
> 
> === modified file 'bzrlib/config.py'
> --- bzrlib/config.py	
> +++ bzrlib/config.py	
> @@ -474,7 +474,15 @@
>          import getpass
>          realname = username = getpass.getuser().decode(bzrlib.user_encoding)
>  
> -    return realname, (username + '@' + socket.gethostname())
> +    try:
> +        f = open(u'/etc/mailname', 'r')
> +        mailname = f.read().strip()
> +        f.close()
> +
> +    except IOError:
> +        mailname = socket.gethostname()
> +
> +    return realname, (username + '@' + mailname)
>  
>  
>  def extract_email_address(e):
> 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 249 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20051218/9e3cc0d2/attachment.pgp 


More information about the bazaar mailing list