#include <lib-lib/debug.h>
#include <lib-lib/rx.h>
+#include <lib-sys/unix.h>
+
#include <lib-ui/curses.h>
#include <lib-ui/enter.h>
#include <lib-ui/menu.h>
if (pw) {
char namebuf[STRING];
- mutt_gecos_name (namebuf, sizeof (namebuf), pw);
- m_strreplace (&a->personal, namebuf);
+ mutt_gecos_name(namebuf, sizeof (namebuf), pw, GecosMask.rx);
+ m_strreplace(&a->personal, namebuf);
}
}
}
if (!Homedir)
Homedir = m_strdup(pw->pw_dir);
- Realname = m_strdup(mutt_gecos_name (rnbuf, sizeof(rnbuf), pw));
+ mutt_gecos_name(rnbuf, sizeof(rnbuf), pw, GecosMask.rx);
+ Realname = m_strdup(rnbuf);
Shell = m_strdup(pw->pw_shell);
endpwent ();
}
noinst_LIBRARIES = libsys.a
-libsys_a_SOURCES = exit.h \
- exit.c \
+libsys_a_SOURCES = exit.h unix.h \
+ exit.c unix.c \
$(___networking_part____) \
mutt_socket.h mutt_tunnel.c mutt_ssl.h \
mutt_socket.c mutt_tunnel.h mutt_ssl.c mutt_ssl_gnutls.c
-noinst_HEADERS = mutt_socket.h mutt_tunnel.c mutt_ssl.h
+noinst_HEADERS = exit.h unix.h \
+ mutt_socket.h mutt_tunnel.c mutt_ssl.h
-include ../cflags.mk
# include "config.h"
#endif
+#include <netinet/in.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/wait.h>
+#include <fcntl.h>
+#include <errno.h>
+
#include <lib-lib/mem.h>
#include <lib-lib/str.h>
#include <lib-lib/macros.h>
#include "mutt.h"
+
+#include "exit.h"
#include "mutt_socket.h"
#include "mutt_tunnel.h"
-
-#include <netinet/in.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/wait.h>
-#include <fcntl.h>
-#include <errno.h>
-
/* -- data types -- */
typedef struct {
pid_t pid;
--- /dev/null
+/*
+ * Copyright notice from original mutt:
+ * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
+ * Copyright (C) 1999-2000 Thomas Roessler <roessler@does-not-exist.org>
+ *
+ * This file is part of mutt-ng, see http://www.muttng.org/.
+ * It's licensed under the GNU General Public License,
+ * please see the file GPL in the top level source directory.
+ */
+
+#include <stdlib.h>
+
+#include <lib-lib/macros.h>
+#include <lib-lib/mem.h>
+#include <lib-lib/str.h>
+
+#include "unix.h"
+
+/* Extract the real name from /etc/passwd's GECOS field.
+ * When set, honor the regular expression in rx,
+ * otherwise assume that the GECOS field is a comma-separated list.
+ * Replace "&" by a capitalized version of the user's login name.
+ */
+ssize_t mutt_gecos_name(char *dst, ssize_t n, struct passwd *pw, rx_t *rx)
+{
+ const char *p, *end;
+ ssize_t len;
+
+ *dst = '\0';
+ len = 0;
+
+ if (!pw->pw_gecos)
+ return 0;
+
+ if (rx) {
+ regmatch_t pat_match[1];
+
+ if (regexec(rx->rx, pw->pw_gecos, 1, pat_match, 0)) {
+ return 0;
+ }
+
+ p = pw->pw_gecos + pat_match[0].rm_so;
+ end = pw->pw_gecos + pat_match[0].rm_so;
+ } else {
+ p = pw->pw_gecos;
+ end = m_strchrnul(pw->pw_gecos, ',');
+ }
+
+ for (;;) {
+ const char *q = MIN(end, m_strchrnul(p, '&'));
+
+ len += m_strncpy(dst + len, n - len, p, q - p);
+ p = q + 1;
+
+ if (!p[-1] || p >= end)
+ break;
+
+ /* p[0] == '&' */
+ len += m_strcpy(dst + len, n - len, pw->pw_name);
+ }
+
+ return len;
+}
--- /dev/null
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * Copyright © 2006 Pierre Habouzit
+ */
+
+#ifndef MUTT_LIB_SYS_UNIX_H
+#define MUTT_LIB_SYS_UNIX_H
+
+#include <sys/types.h>
+#include <pwd.h>
+
+#include <lib-lib/rx.h>
+
+ssize_t mutt_gecos_name(char *dst, ssize_t n, struct passwd *pw, rx_t *rx);
+
+#endif /* MUTT_LIB_SYS_UNIX_H */
return (s);
}
-/* Extract the real name from /etc/passwd's GECOS field.
- * When set, honor the regular expression in GecosMask,
- * otherwise assume that the GECOS field is a
- * comma-separated list.
- * Replace "&" by a capitalized version of the user's login
- * name.
- */
-
-char *mutt_gecos_name (char *dest, ssize_t destlen, struct passwd *pw)
-{
- regmatch_t pat_match[1];
- ssize_t pwnl;
- int idx;
- char *p;
-
- if (!pw || !pw->pw_gecos)
- return NULL;
-
- p_clear(dest, destlen);
-
- if (GecosMask.rx) {
- if (regexec (GecosMask.rx, pw->pw_gecos, 1, pat_match, 0) == 0)
- m_strcpy(dest, MIN(pat_match[0].rm_eo - pat_match[0].rm_so + 1, destlen),
- pw->pw_gecos + pat_match[0].rm_so);
- }
- else if ((p = strchr (pw->pw_gecos, ',')))
- m_strcpy(dest, MIN(destlen, p - pw->pw_gecos + 1), pw->pw_gecos);
- else
- m_strcpy(dest, destlen, pw->pw_gecos);
-
- pwnl = m_strlen(pw->pw_name);
-
- for (idx = 0; dest[idx]; idx++) {
- if (dest[idx] == '&') {
- memmove (&dest[idx + pwnl], &dest[idx + 1],
- MAX (destlen - idx - pwnl - 1, 0));
- memcpy (&dest[idx], pw->pw_name, MIN (destlen - idx - 1, pwnl));
- dest[idx] = toupper ((unsigned char) dest[idx]);
- }
- }
-
- return dest;
-}
-
-
char *mutt_get_parameter (const char *s, PARAMETER * p)
{
for (; p; p = p->next)
char *mutt_expand_path (char *, size_t);
char *_mutt_expand_path (char *, size_t, int);
char *mutt_find_hook (int, const char *);
-char *mutt_gecos_name (char *, ssize_t, struct passwd *);
char *mutt_gen_msgid (void);
char *mutt_get_body_charset (char *, size_t, BODY *);
const char *mutt_get_name (address_t *);