char *spoollocking = DEFAULT_LOCKING;
-/* Cache the username, fullname, and mailbox of the user */
+/* Cache the username, fullname, mailbox name, and mailbox of the user */
static char username[BUFSIZ];
static char fullname[BUFSIZ];
+/* mboxname comes from a Local-Mailbox profile component, or if that
+ doesn't exist, the username. */
+static char mboxname[BUFSIZ];
static char localmbox[2*BUFSIZ+3];
/*
case 0: s--;
/* FALLTHRU */
- case QUOTE:
+ case QUOTE:
*bp = QUOTE;
break;
- default:
+ default:
if (!isdigit ((unsigned char) *s)) {
*bp++ = QUOTE;
*bp = *s;
/*
* Get the username of current user
+ *
+ * If flag is 0, then attempt to extract username from Local-Mailbox profile
+ * component, if present.
+ * If flag is 1, then only use the "proper" local hostname.
*/
char *
-getusername (void)
+getusername (int flag)
{
if (username[0] == '\0')
getuserinfo();
- return username;
+ return flag == 0 ? mboxname : username;
}
}
/*
- * Find the user's username and full name, and cache them.
+ * Find and cache the user's username, full name, and local mbox.
*/
static void
return;
}
-
/* username */
+ if (username[0] == '\0') {
+ strncpy (username, pw->pw_name, sizeof(username));
+ }
+ username[sizeof(username) - 1] = '\0';
+
+ /* localmbox and mboxname */
/* If there's a Local-Mailbox profile component, try to extract
the username from it. But don't try very hard, this assumes
the very simple User Name <user@name.com> form.
if (left_angle_bracket && at_sign && right_angle_bracket) {
if (at_sign > left_angle_bracket &&
at_sign - left_angle_bracket < BUFSIZ) {
- strncpy(username, left_angle_bracket + 1,
+ strncpy(mboxname, left_angle_bracket + 1,
at_sign - left_angle_bracket - 1);
}
}
+ } else {
+ snprintf(localmbox, sizeof(localmbox), "%s <%s@%s>", fullname,
+ username, LocalName(0));
}
-
- if (username[0] == '\0') {
- strncpy (username, pw->pw_name, sizeof(username));
+ localmbox[sizeof(localmbox) - 1] = '\0';
+ if (mboxname[0] == '\0') {
+ strncpy (mboxname, username, sizeof(mboxname));
}
-
- username[sizeof(username) - 1] = '\0';
-
- escape_local_part(username, sizeof(username));
-
+ mboxname[sizeof(mboxname) - 1] = '\0';
+ escape_local_part(mboxname, sizeof(mboxname));
/* fullname */
np = pw->pw_gecos;
strncpy (fullname, cp, sizeof(fullname));
else if ((cp = context_find("Signature")))
strncpy (fullname, cp, sizeof(fullname));
-
fullname[sizeof(fullname) - 1] = '\0';
-
escape_display_name(fullname, sizeof(fullname));
-
-
- /* localmbox, if not using Local-Mailbox */
- if (localmbox[0] == '\0') {
- snprintf(localmbox, sizeof(localmbox), "%s <%s@%s>", fullname,
- username, LocalName(0));
- }
-
- localmbox[sizeof(localmbox) - 1] = '\0';
}
static const char*
setup_test
-#### Use ap to get the username. That will either be what's in the
-#### Local-Mailbox profile component, which we don't use in the test
-#### suite, or the user's login name. ap will escape (quote) it if
-#### needed.
-user=`run_prog ${MH_LIBEXEC_DIR}/ap -format '%(me)' 0`
+#### Remove existing Local-Mailbox: profile component, if any.
+grep -v 'Local-Mailbox: ' "$MH" > "$MH".new
+mv -f "$MH".new "$MH"
+
+user=`id -nu`
set +e
host=`${MH_OBJ_DIR}/test/getcanon`
set -e
myname="Random User <random@user.something.com>"
-#### Remove existing Local-Mailbox: profile component, if any. Then
-#### add one.
-grep -v 'Local-Mailbox: ' "$MH" > "$MH".new
-mv -f "$MH".new "$MH"
+#### Add Local-Mailbox profile component.
echo "Local-Mailbox: ${myname}" >> "$MH"
run_test "echo \
1 "Local-Mailbox test"
output=`run_prog ${MH_LIBEXEC_DIR}/ap -format '%(mymbox{text})' "${user}@${host}"`
-run_test "echo $output" 0 "Local-mailbox overriding user@host test"
+run_test "echo $output" 0 "Local-Mailbox overriding user@host test"
+
+#### Test getusername() when there is a Local-Mailbox profile component.
+run_test 'fmttest -raw -format %(me) ""' "${user}"
# Add an Alternate-Mailbox. This caused ismymbox() to lose the
# Local-Mailbox, Bug #36635: -nocc me doesn't account for