2 * Copyright notice from original mutt:
3 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
4 * Copyright (C) 1999-2000 Thomas Roessler <roessler@does-not-exist.org>
6 * This file is part of mutt-ng, see http://www.muttng.org/.
7 * It's licensed under the GNU General Public License,
8 * please see the file GPL in the top level source directory.
11 #include <lib-lib/lib-lib.h>
17 #include <lib-mime/mime.h>
19 #include <lib-ui/curses.h>
20 #include <lib-ui/enter.h>
29 #include <imap/imap.h>
30 #include <imap/mx_imap.h>
32 #include <lib-crypt/crypt.h>
34 #define SW (option(OPTMBOXPANE)?SidebarWidth:0)
36 /* Modified by blong to accept a "suggestion" for file name. If
37 * that file exists, then construct one with unique name but
38 * keep any extension. This might fail, I guess.
39 * Renamed to mutt_adv_mktemp so I only have to change where it's
40 * called, and not all possible cases.
42 void mutt_adv_mktemp (const char* dir, char *s, ssize_t l)
44 char buf[_POSIX_PATH_MAX];
45 char tmp[_POSIX_PATH_MAX];
50 m_strcpy(buf, sizeof(buf), m_strisempty(dir) ? NONULL(Tempdir) : dir);
51 mutt_expand_path (buf, sizeof (buf));
53 snprintf (s, l, "%s/muttXXXXXX", buf);
57 m_strcpy(tmp, sizeof(tmp), s);
58 mutt_sanitize_filename (tmp, 1);
59 snprintf (s, l, "%s/%s", buf, tmp);
60 if (lstat (s, &sb) == -1 && errno == ENOENT)
62 if ((period = strrchr (tmp, '.')) != NULL)
64 snprintf (s, l, "%s/%s.XXXXXX", buf, tmp);
69 m_strcpy(s + sl, l - sl, period);
74 /* create a send-mode duplicate from a receive-mode body */
76 int mutt_copy_body (FILE * fp, BODY ** tgt, BODY * src)
78 char tmp[_POSIX_PATH_MAX];
81 parameter_t *par, **ppar;
87 m_strcpy(tmp, sizeof(tmp), src->filename);
94 mutt_adv_mktemp (NULL, tmp, sizeof (tmp));
95 if (mutt_save_attachment (fp, src, tmp, 0, NULL) == -1)
101 memcpy (b, src, sizeof (BODY));
105 b->filename = m_strdup(tmp);
106 b->use_disp = use_disp;
109 if (mutt_is_text_part (b))
112 b->xtype = m_strdup(b->xtype);
113 b->subtype = m_strdup(b->subtype);
114 b->form_name = m_strdup(b->form_name);
115 b->filename = m_strdup(b->filename);
116 b->d_filename = m_strdup(b->d_filename);
117 b->description = m_strdup(b->description);
120 * we don't seem to need the HEADER structure currently.
121 * XXX - this may change in the future
127 /* copy parameters */
128 for (par = b->parameter, ppar = &b->parameter; par;
129 ppar = &(*ppar)->next, par = par->next) {
130 *ppar = parameter_new();
131 (*ppar)->attribute = m_strdup(par->attribute);
132 (*ppar)->value = m_strdup(par->value);
135 mutt_stamp_attachment (b);
140 /* returns true if the header contained in "s" is in list "t" */
141 int mutt_matches_ignore (const char *s, string_list_t * t)
143 for (; t; t = t->next) {
144 if (!ascii_strncasecmp (s, t->data, m_strlen(t->data))
151 /* prepend the path part of *path to *lnk */
152 void mutt_expand_link (char *newpath, const char *path, const char *lnk)
154 const char *lb = NULL;
157 /* lnk is full path */
159 m_strcpy(newpath, _POSIX_PATH_MAX, lnk);
163 if ((lb = strrchr (path, '/')) == NULL) {
165 m_strcpy(newpath, _POSIX_PATH_MAX, lnk);
170 memcpy (newpath, path, len);
171 m_strcpy(newpath + len, _POSIX_PATH_MAX - len, lnk);
174 char *mutt_expand_path (char *s, ssize_t slen)
176 return _mutt_expand_path (s, slen, 0);
179 char *_mutt_expand_path (char *s, ssize_t slen, int rx)
181 char p[_POSIX_PATH_MAX] = "";
182 char q[_POSIX_PATH_MAX] = "";
183 char tmp[_POSIX_PATH_MAX];
186 const char *tail = "";
196 if (*(s + 1) == '/' || *(s + 1) == 0) {
197 m_strcpy(p, sizeof(p), NONULL(Homedir));
203 if ((t = strchr (s + 1, '/')))
206 if ((pw = getpwnam (s + 1))) {
207 m_strcpy(p, sizeof(p), pw->pw_dir);
216 /* user not found! */
229 /* if folder = imap[s]://host/: don't append slash */
230 if (imap_is_magic (NONULL (Maildir), NULL) == M_IMAP &&
231 Maildir[m_strlen(Maildir) - 1] == '/')
232 m_strcpy(p, sizeof(p), NONULL(Maildir));
234 snprintf (p, sizeof (p), "%s/", NONULL (Maildir));
240 /* elm compatibility, @ expands alias to user name */
248 if ((alias = alias_lookup(s + 1))) {
250 h->env = envelope_new();
251 h->env->from = h->env->to = alias;
252 mutt_default_save (p, sizeof (p), h);
253 h->env->from = h->env->to = NULL;
255 /* Avoid infinite recursion if the resulting folder starts with '@' */
266 m_strcpy(p, sizeof(p), NONULL(Inbox));
273 m_strcpy(p, sizeof(p), NONULL(Outbox));
280 if (*(s + 1) == '!') {
281 m_strcpy(p, sizeof(p), NONULL(LastFolder));
285 m_strcpy(p, sizeof(p), NONULL(Spoolfile));
293 m_strcpy(p, sizeof(p), NONULL(LastFolder));
300 m_strcpy(p, sizeof(p), NONULL(CurrentFolder));
312 if (rx && *p && !recurse) {
313 rx_sanitize_string (q, sizeof (q), p);
314 snprintf (tmp, sizeof (tmp), "%s%s", q, tail);
317 snprintf (tmp, sizeof (tmp), "%s%s", p, tail);
319 m_strcpy(s, slen, tmp);
326 /* move all the headers from extra not present in base into base */
327 void mutt_merge_envelopes(ENVELOPE* base, ENVELOPE** extra)
329 /* copies each existing element if necessary, and sets the element
330 * to NULL in the source so that envelope_delete doesn't leave us
331 * with dangling pointers. */
332 #define MOVE_ELEM(h) if (!base->h) { base->h = (*extra)->h; (*extra)->h = NULL; }
333 MOVE_ELEM(return_path);
340 MOVE_ELEM(mail_followup_to);
341 MOVE_ELEM(list_post);
342 MOVE_ELEM(message_id);
343 MOVE_ELEM(supersedes);
346 if (!base->refs_changed) {
347 MOVE_ELEM(references);
349 if (!base->irt_changed) {
350 MOVE_ELEM(in_reply_to);
352 /* real_subj is subordinate to subject */
353 if (!base->subject) {
354 base->subject = (*extra)->subject;
355 base->real_subj = (*extra)->real_subj;
356 (*extra)->subject = NULL;
357 (*extra)->real_subj = NULL;
359 /* spam and user headers should never be hashed, and the new envelope may
360 * have better values. Use new versions regardless. */
361 mutt_buffer_free (&base->spam);
362 string_list_wipe(&base->userhdrs);
367 envelope_delete(extra);
370 void _mutt_mktemp (char *s, const char *src, int line)
373 snprintf (s, _POSIX_PATH_MAX, "%s/madmutt-%s-%d-%d-%d-%x%x", NONULL (Tempdir),
374 NONULL (Hostname), (int) getuid (), (int) getpid (), Counter++,
375 (unsigned int) rand(), (unsigned int) rand());
379 /* collapse the pathname using ~ or = when possible */
380 void mutt_pretty_mailbox (char *s)
386 scheme = url_check_scheme (s);
388 if (scheme == U_IMAP || scheme == U_IMAPS) {
389 imap_pretty_mailbox (s);
393 /* if s is an url, only collapse path component */
394 if (scheme != U_UNKNOWN) {
395 p = strchr (s, ':') + 1;
396 if (!strncmp (p, "//", 2))
397 q = strchr (p + 2, '/');
399 q = strchr (p, '\0');
403 /* first attempt to collapse the pathname */
405 if (*p == '/' && p[1] == '/') {
409 else if (p[0] == '/' && p[1] == '.' && p[2] == '/') {
418 if (m_strncmp(s, Maildir, (len = m_strlen(Maildir))) == 0 &&
421 memmove (s, s + len, m_strlen(s + len) + 1);
423 else if (m_strncmp(s, Homedir, (len = m_strlen(Homedir))) == 0 &&
426 memmove (s, s + len - 1, m_strlen(s + len - 1) + 1);
430 void mutt_pretty_size (char *s, ssize_t len, long n)
433 m_strcpy(s, len, "0K");
434 else if (n < 10189) /* 0.1K - 9.9K */
435 snprintf (s, len, "%3.1fK", (n < 103) ? 0.1 : n / 1024.0);
436 else if (n < 1023949) { /* 10K - 999K */
437 /* 51 is magic which causes 10189/10240 to be rounded up to 10 */
438 snprintf (s, len, "%ldK", (n + 51) / 1024);
440 else if (n < 10433332) /* 1.0M - 9.9M */
441 snprintf (s, len, "%3.1fM", n / 1048576.0);
444 /* (10433332 + 52428) / 1048576 = 10 */
445 snprintf (s, len, "%ldM", (n + 52428) / 1048576);
449 void mutt_expand_file_fmt(char *dest, ssize_t destlen,
450 const char *fmt, const char *src)
452 char tmp[LONG_STRING];
454 mutt_quote_filename(tmp, sizeof(tmp), src);
455 mutt_expand_fmt(dest, destlen, fmt, tmp);
458 void mutt_expand_fmt(char *dst, ssize_t dlen,
459 const char *fmt, const char *src)
464 while (*fmt && pos < dlen - 1) {
469 pos += m_strcpy(dst + pos, dlen - pos, src);
487 pos += m_strcpy(dst + pos, dlen - pos, " ");
488 pos += m_strcpy(dst + pos, dlen - pos, src);
492 /* return 0 on success, -1 on abort, 1 on error */
493 int mutt_check_overwrite (const char *attname, const char *path,
494 char *fname, ssize_t flen, int *append,
498 char tmp[_POSIX_PATH_MAX];
501 m_strcpy(fname, flen, path);
502 if (access (fname, F_OK) != 0)
504 if (stat (fname, &st) != 0)
506 if (S_ISDIR (st.st_mode)) {
508 switch (mutt_multi_choice
509 (_("File is a directory, save under it? [(y)es, (n)o, (a)ll]"),
512 m_strreplace(directory, fname);
527 mutt_yesorno (_("File is a directory, save under it?"),
529 return (rc == M_NO) ? 1 : -1;
531 if (!attname || !attname[0]) {
533 if (mutt_get_field (_("File under directory: "), tmp, sizeof (tmp),
534 M_FILE | M_CLEAR) != 0 || !tmp[0])
536 mutt_concat_path(fname, flen, path, tmp);
539 mutt_concat_path(fname, flen, path, mutt_basename(attname));
542 if (*append == 0 && access (fname, F_OK) == 0) {
543 switch (mutt_multi_choice
544 (_("File exists, (o)verwrite, (a)ppend, or (c)ancel?"), _("oac")))
552 *append = M_SAVE_APPEND;
554 case 1: /* overwrite */
555 *append = M_SAVE_OVERWRITE;
562 void mutt_save_path(char *d, ssize_t dsize, address_t *a)
564 if (a && a->mailbox) {
565 m_strcpy(d, dsize, a->mailbox);
567 if (!option(OPTSAVEADDRESS)) {
568 char *p = strpbrk(d, "%@");
578 void mutt_safe_path(char *s, ssize_t l, address_t *a)
580 mutt_save_path(s, l, a);
583 if (*s == '/' || ISSPACE(*s) || !isprint((unsigned char)*s))
589 void mutt_FormatString (char *dest, /* output buffer */
590 ssize_t destlen, /* output buffer len */
591 const char *src, /* template string */
592 format_t * callback, /* callback for processing */
593 unsigned long data, /* callback data */
595 { /* callback flags */
596 char prefix[SHORT_STRING], buf[LONG_STRING], *cp, *wptr = dest, ch;
597 char ifstring[SHORT_STRING], elsestring[SHORT_STRING];
598 ssize_t wlen, wid, count, col, len;
601 destlen--; /* save room for the terminal \0 */
602 wlen = (flags & M_FORMAT_ARROWCURSOR && option (OPTARROWCURSOR)) ? 3 : 0;
605 while (*src && wlen < destlen) {
616 flags |= M_FORMAT_OPTIONAL;
620 flags &= ~M_FORMAT_OPTIONAL;
622 /* eat the format string */
625 while (count < ssizeof (prefix) &&
626 (isdigit ((unsigned char) *src) || *src == '.' || *src == '-'))
635 break; /* bad format */
637 ch = *src++; /* save the character to switch on */
639 if (flags & M_FORMAT_OPTIONAL) {
641 break; /* bad format */
644 /* eat the `if' part of the string */
647 while (count < ssizeof (ifstring) && *src && *src != '?'
654 /* eat the `else' part of the string (optional) */
656 src++; /* skip the & */
659 while (count < ssizeof (elsestring) && *src && *src != '?') {
666 break; /* bad format */
668 src++; /* move past the trailing `?' */
671 /* handle generic cases first */
673 /* right justify to EOL */
674 ch = *src++; /* pad char */
675 /* calculate space left on line. if we've already written more data
676 than will fit on the line, ignore the rest of the line */
677 if (DrawFullLine || option (OPTSTATUSONTOP))
678 count = (COLS < destlen ? COLS : destlen);
680 count = ((COLS - SW) < destlen ? (COLS - SW) : destlen);
682 count -= col; /* how many columns left on this line */
683 mutt_FormatString (buf, sizeof (buf), src, callback, data, flags);
686 count -= wid; /* how many chars to pad */
687 memset (wptr, ch, count);
691 if (wid + wlen > destlen)
692 len = destlen - wlen;
695 memcpy (wptr, buf, len);
698 col += mutt_strwidth (buf);
700 break; /* skip rest of input */
702 else if (ch == '|') {
707 if (destlen > wlen) {
708 count = destlen - wlen;
709 memset (wptr, ch, count);
712 break; /* skip rest of input */
718 while (ch == '_' || ch == ':') {
727 /* use callback function to handle this case */
729 callback (buf, sizeof (buf), ch, src, prefix, ifstring, elsestring,
742 if ((len = m_strlen(buf)) + wlen > destlen)
743 len = (destlen - wlen > 0) ? (destlen - wlen) : 0;
745 memcpy (wptr, buf, len);
748 col += mutt_strwidth (buf);
751 else if (*src == '\\') {
780 unsigned int bar = strcspn(src, "%\\");
781 char *bar2 = p_dupstr(src, bar);
787 col += mutt_strwidth (bar2);
794 if (flags & M_FORMAT_MAKEPRINT) {
795 /* Make sure that the string is printable by changing all non-printable
796 chars to dots, or spaces for non-printable whitespace */
797 for (cp = dest; *cp; cp++)
798 if (!isprint(*cp) && !((flags & M_FORMAT_TREE) && (*cp <= M_TREE_MAX)))
799 *cp = isspace ((unsigned char) *cp) ? ' ' : '.';
804 /* returns 0 if OK to proceed, -1 to abort, 1 to retry */
805 int mutt_save_confirm (const char *s, struct stat *st)
807 char tmp[_POSIX_PATH_MAX];
812 magic = mx_get_magic (s);
814 if (magic == M_POP) {
815 mutt_error _("Can't save message to POP mailbox.");
821 if (magic == M_NNTP) {
822 mutt_error _("Can't save message to newsserver.");
828 if (magic > 0 && !mx_access (s, W_OK)) {
829 if (option (OPTCONFIRMAPPEND) &&
830 (!TrashPath || (m_strcmp(s, TrashPath) != 0))) {
831 /* if we're appending to the trash, there's no point in asking */
832 snprintf (tmp, sizeof (tmp), _("Append messages to %s?"), s);
833 if ((rc = mutt_yesorno (tmp, M_YES)) == M_NO)
840 if (stat (s, st) != -1) {
842 mutt_error (_("%s is not a mailbox!"), s);
852 if (errno == ENOENT) {
853 if (option (OPTCONFIRMCREATE)) {
854 snprintf (tmp, sizeof (tmp), _("Create %s?"), s);
855 if ((rc = mutt_yesorno (tmp, M_YES)) == M_NO)
868 CLEARLINE (LINES - 1);
872 void mutt_sleep (short s)
874 sleep(MAX(s, SleepTime));
877 /* Decrease a file's modification time by 1 second */
878 time_t mutt_decrease_mtime (const char *f, struct stat *st)
885 if (stat (f, &_st) == -1)
890 if ((mtime = st->st_mtime) == time (NULL)) {
893 utim.modtime = mtime;
900 /* sets mtime of 'to' to mtime of 'from' */
901 void mutt_set_mtime (const char* from, const char* to) {
905 if (stat (from, &st) != -1) {
906 utim.actime = st.st_mtime;
907 utim.modtime = st.st_mtime;
912 const char *mutt_make_version (int full)
914 static char vstring[STRING];
917 snprintf (vstring, sizeof (vstring),
918 "Madmutt/%s-r%s (based on Mutt 1.5.11)",
919 MUTT_VERSION, MUTT_REVISION);
921 snprintf (vstring, sizeof (vstring), "Madmutt/%s-%s",
922 MUTT_VERSION, MUTT_REVISION);
926 void mutt_free_spam_list (SPAM_LIST ** list)
934 *list = (*list)->next;
936 p_delete(&p->template);
941 int mutt_match_spam_list (const char *s, SPAM_LIST * l, char *text, int x)
943 static regmatch_t *pmatch = NULL;
944 static int nmatch = 0;
953 for (; l; l = l->next) {
954 /* If this pattern needs more matches, expand pmatch. */
955 if (l->nmatch > nmatch) {
956 p_realloc(&pmatch, l->nmatch);
960 /* Does this pattern match? */
961 if (regexec(l->rx->rx, s, l->nmatch, (regmatch_t *)pmatch, (int) 0) == 0)
963 /* Copy template into text, with substitutions. */
964 for (p = l->template; *p;) {
966 n = atoi (++p); /* find pmatch index */
967 while (isdigit ((unsigned char) *p))
968 ++p; /* skip subst token */
969 for (i = pmatch[n].rm_so; (i < pmatch[n].rm_eo) && (tlen < x); i++)
984 int mutt_cmp_header (const HEADER * h1, const HEADER * h2) {
986 if (h1->received != h2->received ||
987 h1->date_sent != h2->date_sent ||
988 h1->content->length != h2->content->length ||
989 h1->lines != h2->lines ||
990 h1->zhours != h2->zhours ||
991 h1->zminutes != h2->zminutes ||
992 h1->zoccident != h2->zoccident ||
993 h1->mime != h2->mime ||
994 !mutt_cmp_env (h1->env, h2->env) ||
995 !mutt_cmp_body (h1->content, h2->content))
1001 if (h1 == NULL && h2 == NULL)
1008 /* return 1 if address lists are strictly identical */
1009 int mutt_cmp_addr (const address_t * a, const address_t * b)
1012 if (m_strcmp(a->mailbox, b->mailbox) ||
1013 m_strcmp(a->personal, b->personal))
1025 int mutt_cmp_list (const string_list_t * a, const string_list_t * b)
1028 if (m_strcmp(a->data, b->data))
1040 int mutt_cmp_env (const ENVELOPE * e1, const ENVELOPE * e2)
1043 if (m_strcmp(e1->message_id, e2->message_id) ||
1044 m_strcmp(e1->subject, e2->subject) ||
1045 !mutt_cmp_list (e1->references, e2->references) ||
1046 !mutt_cmp_addr (e1->from, e2->from) ||
1047 !mutt_cmp_addr (e1->sender, e2->sender) ||
1048 !mutt_cmp_addr (e1->reply_to, e2->reply_to) ||
1049 !mutt_cmp_addr (e1->to, e2->to) ||
1050 !mutt_cmp_addr (e1->cc, e2->cc) ||
1051 !mutt_cmp_addr (e1->return_path, e2->return_path))
1057 if (e1 == NULL && e2 == NULL)
1064 int mutt_cmp_body (const BODY * b1, const BODY * b2)
1066 if (b1->type != b2->type ||
1067 b1->encoding != b2->encoding ||
1068 m_strcmp(b1->subtype, b2->subtype) ||
1069 m_strcmp(b1->description, b2->description) ||
1070 !parameter_equal(b1->parameter, b2->parameter) ||
1071 b1->length != b2->length)
1076 int mutt_extract_token(BUFFER *dest, BUFFER *tok, int flags)
1079 char qc = 0; /* quote char */
1082 /* reset the destination pointer to the beginning of the buffer */
1083 dest->dptr = dest->data;
1085 tok->dptr = vskipspaces(tok->dptr);
1086 while ((ch = *tok->dptr)) {
1088 if ((ISSPACE(ch) && !(flags & M_TOKEN_SPACE))
1089 || (ch == '#' && !(flags & M_TOKEN_COMMENT))
1090 || (ch == '=' && (flags & M_TOKEN_EQUAL))
1091 || (ch == ';' && !(flags & M_TOKEN_SEMICOLON))
1092 || ((flags & M_TOKEN_PATTERN) && strchr("~=!|", ch)))
1101 qc = 0; /* end of quote */
1103 if (!qc && (ch == '\'' || ch == '"') && !(flags & M_TOKEN_QUOTE)) {
1106 if (ch == '\\' && qc != '\'') {
1108 return -1; /* premature end of token */
1110 switch (ch = *tok->dptr++) {
1114 return -1; /* premature end of token */
1115 mutt_buffer_addch(dest,
1116 (ascii_toupper(*tok->dptr) - 'A' + 1) & 0x7f);
1120 mutt_buffer_addch(dest, '\r');
1123 mutt_buffer_addch(dest, '\n');
1126 mutt_buffer_addch(dest, '\t');
1129 mutt_buffer_addch(dest, '\f');
1132 mutt_buffer_addch(dest, '\033');
1135 if (isdigit((unsigned char)ch)
1136 && isdigit((unsigned char)*tok->dptr)
1137 && isdigit((unsigned char)*(tok->dptr + 1)))
1139 mutt_buffer_addch(dest, (ch << 6) + (*tok->dptr << 3) +
1140 *(tok->dptr + 1) - 3504);
1143 mutt_buffer_addch(dest, ch);
1147 if (ch == '^' && (flags & M_TOKEN_CONDENSE)) {
1149 return -1; /* premature end of token */
1152 mutt_buffer_addch(dest, ch);
1155 mutt_buffer_addch(dest, '\033');
1157 if (isalpha((unsigned char)ch)) {
1158 mutt_buffer_addch(dest, ascii_toupper(ch) - 'A' + 1);
1160 mutt_buffer_addch(dest, '^');
1161 mutt_buffer_addch(dest, ch);
1164 if (ch == '`' && (!qc || qc == '"')) {
1174 if ((pc = strpbrk(pc, "\\`"))) {
1175 /* skip any quoted chars */
1179 } while (pc && *pc != '`');
1184 cmd = p_dupstr(tok->dptr, pc - tok->dptr);
1185 if ((pid = mutt_create_filter(cmd, NULL, &fp, NULL)) < 0) {
1195 expn.data = mutt_read_line(NULL, &expn.dsize, fp, &line);
1197 mutt_wait_filter(pid);
1199 /* if we got output, make a new string consiting of the shell ouptput
1200 plus whatever else was left on the original line */
1201 /* BUT: If this is inside a quoted string, directly add output to
1203 if (expn.data && qc) {
1204 mutt_buffer_addstr(dest, expn.data);
1205 p_delete(&expn.data);
1208 expnlen = m_strlen(expn.data);
1209 tok->dsize = expnlen + m_strlen(tok->dptr) + 1;
1210 ptr = xmalloc(tok->dsize);
1211 memcpy(ptr, expn.data, expnlen);
1212 strcpy(ptr + expnlen, tok->dptr); /* __STRCPY_CHECKED__ */
1214 p_delete(&tok->data);
1217 tok->destroy = 1; /* mark that the caller should destroy this data */
1219 p_delete(&expn.data);
1222 if (ch == '$' && (!qc || qc == '"')
1223 && (*tok->dptr == '{' || isalpha((unsigned char)*tok->dptr)))
1225 char *env = NULL, *var = NULL;
1227 if (*tok->dptr == '{') {
1229 if ((pc = strchr (tok->dptr, '}'))) {
1230 var = p_dupstr(tok->dptr, pc - tok->dptr);
1234 for (pc = tok->dptr; isalnum((unsigned char)*pc) || *pc == '_';
1236 var = p_dupstr(tok->dptr, pc - tok->dptr);
1241 if ((env = getenv (var))
1242 || (mutt_option_value (var, tmp, sizeof (tmp)) && (env = tmp)))
1244 mutt_buffer_addstr (dest, env);
1249 mutt_buffer_addch(dest, ch);
1252 mutt_buffer_addch(dest, 0); /* terminate the string */
1253 tok->dptr = vskipspaces(tok->dptr);