processing.
#include "mutt_regex.h"
#include "mutt_curses.h"
-#include <pwd.h>
#include <string.h>
ADDRESS *mutt_lookup_alias (const char *s)
if (pw)
{
- regmatch_t pat_match[1];
-
- /* Use regular expression to parse Gecos field. This result of the
- * parsing will be used as the personal ID string when the alias is
- * expanded.
- */
- if (regexec (GecosMask.rx, pw->pw_gecos, 1, pat_match, 0) == 0)
- {
- /* Malloc enough for the matching pattern + terminating NULL */
- a->personal = safe_malloc ((pat_match[0].rm_eo -
- pat_match[0].rm_so) + 1);
-
- strfcpy (a->personal, pw->pw_gecos + pat_match[0].rm_so,
- pat_match[0].rm_eo - pat_match[0].rm_so + 1);
- }
-
+ char namebuf[STRING];
+
+ mutt_gecos_name (namebuf, sizeof (namebuf), pw);
+ mutt_str_replace (&a->personal, namebuf);
+
#ifdef EXACT_ADDRESS
FREE (&a->val);
#endif
#include <ctype.h>
#include <unistd.h>
#include <sys/stat.h>
-#include <pwd.h>
-#include <grp.h>
static struct mapping_t FolderHelp[] = {
{ N_("Exit"), OP_EXIT },
#include "init.h"
#include "mailbox.h"
-#include <pwd.h>
#include <ctype.h>
#include <stdlib.h>
#include <unistd.h>
/* Get some information about the user */
if ((pw = getpwuid (getuid ())))
{
+ char rnbuf[STRING];
+
Username = safe_strdup (pw->pw_name);
if (!Homedir)
Homedir = safe_strdup (pw->pw_dir);
- if ((p = strchr (pw->pw_gecos, ',')))
- Realname = mutt_substrdup (pw->pw_gecos, p);
- else
- Realname = safe_strdup (pw->pw_gecos);
+
+ Realname = safe_strdup (mutt_gecos_name (rnbuf, sizeof (rnbuf), pw));
Shell = safe_strdup (pw->pw_shell);
}
else
#include <stdlib.h>
#include <sys/wait.h>
#include <errno.h>
-#include <pwd.h>
#include <sys/stat.h>
#include <fcntl.h>
+#include <pwd.h>
#include "lib.h"
#include <posix1_lim.h>
#endif
+#include <pwd.h>
+#include <grp.h>
+
#include "rfc822.h"
#include "hash.h"
#include <stdlib.h>
#include <sys/wait.h>
#include <errno.h>
-#include <pwd.h>
#include <sys/stat.h>
#include <fcntl.h>
+#define MIN(a,b) ((a) < (b) ? (a) : (b))
+#define MAX(a,b) ((a) < (b) ? (b) : (a))
+
BODY *mutt_new_body (void)
{
BODY *p = (BODY *) safe_calloc (1, sizeof (BODY));
}
+char *mutt_gecos_name (char *dest, size_t destlen, struct passwd *pw)
+{
+ regmatch_t pat_match[1];
+ size_t pwnl;
+ int idx;
+ char *p;
+
+ if (!pw || !pw->pw_gecos)
+ return NULL;
+
+ memset (dest, 0, destlen);
+
+ if (GecosMask.rx)
+ {
+ if (regexec (GecosMask.rx, pw->pw_gecos, 1, pat_match, 0) == 0)
+ strfcpy (dest, pw->pw_gecos + pat_match[0].rm_so,
+ MIN (pat_match[0].rm_eo - pat_match[0].rm_so + 1, destlen));
+ }
+ else if ((p = strchr (pw->pw_gecos, ',')))
+ strfcpy (dest, pw->pw_gecos, MIN (destlen, p - pw->pw_gecos + 1));
+ else
+ strfcpy (dest, pw->pw_gecos, destlen);
+
+ pwnl = 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 (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 *, size_t, struct passwd *);
char *mutt_gen_msgid (void);
char *mutt_get_name (ADDRESS *);
char *mutt_get_parameter (const char *, PARAMETER *);