From: Pierre Habouzit Date: Thu, 29 Mar 2007 22:33:17 +0000 (+0200) Subject: Deal with $hostname and $shorthost X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=b6980caf7b13994c57957872876cdecc21e54a82;p=apps%2Fmadmutt.git Deal with $hostname and $shorthost Signed-off-by: Pierre Habouzit --- diff --git a/alias.cpkg b/alias.cpkg index 7f9843e..bab4a49 100644 --- a/alias.cpkg +++ b/alias.cpkg @@ -132,7 +132,7 @@ int mutt_addr_is_user(address_t *addr) return 0; if (!ascii_strcasecmp(addr->mailbox, MCore.username) - || string_is_address(addr->mailbox, MCore.username, Hostname) + || string_is_address(addr->mailbox, MCore.username, MCore.shorthost) || string_is_address(addr->mailbox, MCore.username, mutt_fqdn(0)) || string_is_address(addr->mailbox, MCore.username, mutt_fqdn(1)) || (From && !ascii_strcasecmp(From->mailbox, addr->mailbox))) diff --git a/compose.c b/compose.c index 9d37626..b0e93d4 100644 --- a/compose.c +++ b/compose.c @@ -426,7 +426,7 @@ static const char *compose_format_str (char *buf, ssize_t buflen, char op, case 'h': /* hostname */ snprintf (fmt, sizeof (fmt), "%%%ss", prefix); - snprintf (buf, buflen, fmt, NONULL (Hostname)); + snprintf (buf, buflen, fmt, NONULL(MCore.shorthost)); break; case 'l': /* approx length of current message in bytes */ diff --git a/globals.h b/globals.h index ade60c8..ef9b7b9 100644 --- a/globals.h +++ b/globals.h @@ -38,7 +38,6 @@ WHERE char *FolderFormat; WHERE char *ForwFmt; WHERE char *Fqdn; WHERE char *HdrFmt; -WHERE char *Hostname; WHERE char *ImapAuthenticators INITVAL (NULL); WHERE char *ImapDelimChars INITVAL (NULL); diff --git a/init.c b/init.c index 2999e7e..ff02dce 100644 --- a/init.c +++ b/init.c @@ -11,7 +11,6 @@ */ #include -#include #include #include @@ -2142,7 +2141,6 @@ static int mutt_execute_commands (string_list_t * p) void mutt_init (int skip_sys_rc, string_list_t * commands) { struct passwd *pw; - struct utsname utsname; const char *p; char buffer[STRING], error[STRING]; int default_rc = 0, need_pause = 0; @@ -2172,27 +2170,6 @@ void mutt_init (int skip_sys_rc, string_list_t * commands) Realname = m_strdup(rnbuf); } - /* And about the host... */ - uname (&utsname); - /* some systems report the FQDN instead of just the hostname */ - if ((p = strchr (utsname.nodename, '.'))) { - Hostname = p_dupstr(utsname.nodename, p - utsname.nodename); - p++; - m_strcpy(buffer, sizeof(buffer), p); /* save the domain for below */ - } - else - Hostname = m_strdup(utsname.nodename); - - if (!p && getdnsdomainname(buffer, sizeof(buffer)) == -1) - Fqdn = m_strdup("@"); - else - if (*buffer != '@') { - Fqdn = p_new(char, m_strlen(buffer) + m_strlen(Hostname) + 2); - sprintf (Fqdn, "%s.%s", NONULL(Hostname), buffer); - } - else - Fqdn = m_strdup(NONULL (Hostname)); - #ifdef USE_NNTP { FILE *f; @@ -2214,11 +2191,9 @@ void mutt_init (int skip_sys_rc, string_list_t * commands) NewsServer = m_strdup(p); #endif - if ((p = getenv ("MAIL"))) - Spoolfile = m_strdup(p); - else if ((p = getenv ("MAILDIR"))) + if ((p = getenv("MAIL") ?: getenv("MAILDIR"))) { Spoolfile = m_strdup(p); - else { + } else { #ifdef HOMESPOOL mutt_concat_path(buffer, sizeof(buffer), NONULL(MCore.homedir), MAILPATH); #else diff --git a/init.h b/init.h index 9d6b533..f083620 100644 --- a/init.h +++ b/init.h @@ -778,7 +778,6 @@ struct option_t MuttVars[] = { ** top of threads in the thread tree. Note that when $$hide_limited is ** \fIset\fP, this option will have no effect. */ - {"history", DT_NUM, R_NONE, UL &HistSize, "10" }, /* ** .pp ** This variable controls the size (in number of strings remembered) of @@ -791,15 +790,6 @@ struct option_t MuttVars[] = { ** This variable controls whether or not a \fTMail-Followup-To:\fP header field is ** honored when group-replying to a message. */ - {"hostname", DT_STR, R_NONE, UL &Fqdn, "" }, - /* - ** .pp - ** Specifies the hostname to use after the ``\fT@\fP'' in local e-mail - ** addresses and during generation of \fTMessage-ID:\fP headers. - ** .pp - ** Please be sure to really know what you are doing when changing this variable - ** to configure a custom domain part of Message-IDs. - */ {"ignore_list_reply_to", DT_BOOL, R_NONE, OPTIGNORELISTREPLYTO, "no" }, /* ** .pp diff --git a/lib-lua/lua-token.sh b/lib-lua/lua-token.sh index bec6a1a..7fd5e55 100644 --- a/lib-lua/lua-token.sh +++ b/lib-lua/lua-token.sh @@ -129,12 +129,14 @@ exit 0 ## gecos_mask ## hcache_backend ## homedir +## hostname ## no ## quit ## send_charset ## sendmail ## sendmail_wait ## shell +## shorthost ## sysconfdir ## tmpdir ## use_8bitmime diff --git a/lib-lua/madmutt.cpkg b/lib-lua/madmutt.cpkg index daa101f..d083405 100644 --- a/lib-lua/madmutt.cpkg +++ b/lib-lua/madmutt.cpkg @@ -18,11 +18,14 @@ */ #include -#include +#include #include #include +#include +#include + #include "../mutt.h" @import "base.cpkg" @@ -44,6 +47,34 @@ static char *madmutt_init_homedir(void) return m_strdup(pw ? pw->pw_dir : (getenv("HOME") ?: "/")); } +static char *madmutt_init_shorthost(void) +{ + struct utsname utsname; + const char *p; + + /* some systems report the FQDN instead of just the hostname */ + uname(&utsname); + p = strchrnul(utsname.nodename, '.'); + return p_dupstr(utsname.nodename, p - utsname.nodename); +} + +static char *madmutt_init_hostname(void) +{ + char buffer[STRING]; + + if (getdnsdomainname(buffer, sizeof(buffer)) < 0) + return m_strdup("@"); + + if (*buffer != '@') { + int len = m_strlen(buffer) + m_strlen(MCore.shorthost) + 2; + char *res = p_new(char, len); + snprintf(res, len, "%s.%s", NONULL(MCore.shorthost), buffer); + return res; + } + + return m_strdup(NONULL(MCore.shorthost)); +} + #if defined(HAVE_QDBM) # define HCACHE_BACKEND "qdbm" #elif defined(HAVE_GDBM) @@ -106,12 +137,20 @@ static char *madmutt_init_homedir(void) */ path_t shell = madmutt_init_shell(); - /* TODO: document */ path_t username = madmutt_init_username(); - - /* TODO: document */ path_t homedir = madmutt_init_homedir(); + /* + ** .pp + ** Specifies the hostname to use after the ``\fT@\fP'' in local e-mail + ** addresses and during generation of \fTMessage-ID:\fP headers. + ** .pp + ** Please be sure to really know what you are doing when changing this variable + ** to configure a custom domain part of Message-IDs. + */ + string_t hostname = madmutt_init_hostname(); + string_t shorthost = madmutt_init_shorthost(); + /* ** .pp ** This variable allows you to specify where Madmutt will place its diff --git a/lib-mx/mh.c b/lib-mx/mh.c index 9108ed5..38ad5e3 100644 --- a/lib-mx/mh.c +++ b/lib-mx/mh.c @@ -164,7 +164,7 @@ static int mh_mkstemp (CONTEXT * dest, FILE ** fp, char **tgt) for (;;) { snprintf (path, _POSIX_PATH_MAX, "%s/.mutt-%s-%d-%d", - dest->path, NONULL (Hostname), (int) getpid (), Counter++); + dest->path, NONULL(MCore.shorthost), (int) getpid (), Counter++); umask (Umask); if ((fd = open (path, O_WRONLY | O_EXCL | O_CREAT, 0666)) == -1) { if (errno != EEXIST) { @@ -919,7 +919,7 @@ static int maildir_open_new_message (MESSAGE * msg, CONTEXT * dest, HEADER * hdr for (;;) { snprintf (path, _POSIX_PATH_MAX, "%s/tmp/%s.%ld.%u_%d.%s%s", dest->path, subdir, (long) time (NULL), - (unsigned int) getpid (), Counter++, NONULL (Hostname), suffix); + (unsigned int) getpid (), Counter++, NONULL (MCore.shorthost), suffix); umask (Umask); if ((fd = open (path, O_WRONLY | O_EXCL | O_CREAT, 0666)) == -1) { @@ -992,7 +992,7 @@ static int maildir_commit_message (MESSAGE * msg, CONTEXT * ctx, HEADER * hdr) for (;;) { snprintf (path, _POSIX_PATH_MAX, "%s/%ld.%u_%d.%s%s", subdir, (long) time (NULL), (unsigned int) getpid (), Counter++, - NONULL (Hostname), suffix); + NONULL (MCore.shorthost), suffix); snprintf (full, _POSIX_PATH_MAX, "%s/%s", ctx->path, path); if (safe_rename (msg->path, full) == 0) { diff --git a/lib-ui/status.c b/lib-ui/status.c index 02d38b2..2ca8f9d 100644 --- a/lib-ui/status.c +++ b/lib-ui/status.c @@ -98,7 +98,7 @@ status_format_str(char *buf, ssize_t buflen, char op, const char *src, case 'h': snprintf (fmt, sizeof (fmt), "%%%ss", prefix); - snprintf (buf, buflen, fmt, NONULL (Hostname)); + snprintf (buf, buflen, fmt, NONULL (MCore.shorthost)); break; case 'f': diff --git a/sendlib.c b/sendlib.c index 669140d..1802e1d 100644 --- a/sendlib.c +++ b/sendlib.c @@ -1539,22 +1539,22 @@ static void encode_headers (string_list_t * h) } } -const char *mutt_fqdn (short may_hide_host) +const char *mutt_fqdn(short may_hide_host) { char *p = NULL, *q; - if (Fqdn && Fqdn[0] != '@') { - p = Fqdn; + if (MCore.hostname && MCore.hostname[0] != '@') { + p = MCore.hostname; if (may_hide_host && option (OPTHIDDENHOST)) { - if ((p = strchr (Fqdn, '.'))) + if ((p = strchr(MCore.hostname, '.'))) p++; /* sanity check: don't hide the host if the fqdn is something like detebe.org. */ - if (!p || !(q = strchr (p, '.'))) - p = Fqdn; + if (!p || !(q = strchr(p, '.'))) + p = MCore.hostname; } } @@ -1657,7 +1657,7 @@ static char *mutt_gen_msgid (void) const char *fqdn; if (!(fqdn = mutt_fqdn(0))) - fqdn = NONULL(Hostname); + fqdn = NONULL(MCore.shorthost); mutt_gen_localpart(localpart, sizeof(localpart), MsgIdFormat); snprintf(buf, sizeof(buf), "<%s@%s>", localpart, fqdn);