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>
22 #include <lib-sys/unix.h>
31 #include <imap/imap.h>
32 #include <imap/mx_imap.h>
34 #include <lib-crypt/crypt.h>
36 #define SW (option(OPTMBOXPANE)?SidebarWidth:0)
38 /* Modified by blong to accept a "suggestion" for file name. If
39 * that file exists, then construct one with unique name but
40 * keep any extension. This might fail, I guess.
41 * Renamed to mutt_adv_mktemp so I only have to change where it's
42 * called, and not all possible cases.
44 void mutt_adv_mktemp (const char* dir, char *s, ssize_t l)
46 char buf[_POSIX_PATH_MAX];
47 char tmp[_POSIX_PATH_MAX];
52 m_strcpy(buf, sizeof(buf), m_strisempty(dir) ? NONULL(Tempdir) : dir);
53 mutt_expand_path (buf, sizeof (buf));
55 snprintf (s, l, "%s/muttXXXXXX", buf);
59 m_strcpy(tmp, sizeof(tmp), s);
60 mutt_sanitize_filename (tmp, 1);
61 snprintf (s, l, "%s/%s", buf, tmp);
62 if (lstat (s, &sb) == -1 && errno == ENOENT)
64 if ((period = strrchr (tmp, '.')) != NULL)
66 snprintf (s, l, "%s/%s.XXXXXX", buf, tmp);
71 m_strcpy(s + sl, l - sl, period);
76 /* create a send-mode duplicate from a receive-mode body */
78 int mutt_copy_body (FILE * fp, BODY ** tgt, BODY * src)
80 char tmp[_POSIX_PATH_MAX];
83 parameter_t *par, **ppar;
89 m_strcpy(tmp, sizeof(tmp), src->filename);
96 mutt_adv_mktemp (NULL, tmp, sizeof (tmp));
97 if (mutt_save_attachment (fp, src, tmp, 0, NULL) == -1)
103 memcpy (b, src, sizeof (BODY));
107 b->filename = m_strdup(tmp);
108 b->use_disp = use_disp;
111 if (mutt_is_text_part (b))
114 b->xtype = m_strdup(b->xtype);
115 b->subtype = m_strdup(b->subtype);
116 b->form_name = m_strdup(b->form_name);
117 b->filename = m_strdup(b->filename);
118 b->d_filename = m_strdup(b->d_filename);
119 b->description = m_strdup(b->description);
122 * we don't seem to need the HEADER structure currently.
123 * XXX - this may change in the future
129 /* copy parameters */
130 for (par = b->parameter, ppar = &b->parameter; par;
131 ppar = &(*ppar)->next, par = par->next) {
132 *ppar = parameter_new();
133 (*ppar)->attribute = m_strdup(par->attribute);
134 (*ppar)->value = m_strdup(par->value);
137 mutt_stamp_attachment (b);
142 /* returns true if the header contained in "s" is in list "t" */
143 int mutt_matches_ignore (const char *s, string_list_t * t)
145 for (; t; t = t->next) {
146 if (!ascii_strncasecmp (s, t->data, m_strlen(t->data))
153 /* prepend the path part of *path to *lnk */
154 void mutt_expand_link (char *newpath, const char *path, const char *lnk)
156 const char *lb = NULL;
159 /* lnk is full path */
161 m_strcpy(newpath, _POSIX_PATH_MAX, lnk);
165 if ((lb = strrchr (path, '/')) == NULL) {
167 m_strcpy(newpath, _POSIX_PATH_MAX, lnk);
172 memcpy (newpath, path, len);
173 m_strcpy(newpath + len, _POSIX_PATH_MAX - len, lnk);
176 char *mutt_expand_path (char *s, ssize_t slen)
178 return _mutt_expand_path (s, slen, 0);
181 char *_mutt_expand_path (char *s, ssize_t slen, int rx)
183 char p[_POSIX_PATH_MAX] = "";
184 char q[_POSIX_PATH_MAX] = "";
185 char tmp[_POSIX_PATH_MAX];
188 const char *tail = "";
198 if (*(s + 1) == '/' || *(s + 1) == 0) {
199 m_strcpy(p, sizeof(p), NONULL(Homedir));
205 if ((t = strchr (s + 1, '/')))
208 if ((pw = getpwnam (s + 1))) {
209 m_strcpy(p, sizeof(p), pw->pw_dir);
218 /* user not found! */
231 /* if folder = imap[s]://host/: don't append slash */
232 if (imap_is_magic (NONULL (Maildir), NULL) == M_IMAP &&
233 Maildir[m_strlen(Maildir) - 1] == '/')
234 m_strcpy(p, sizeof(p), NONULL(Maildir));
236 snprintf (p, sizeof (p), "%s/", NONULL (Maildir));
242 /* elm compatibility, @ expands alias to user name */
250 if ((alias = alias_lookup(s + 1))) {
252 h->env = envelope_new();
253 h->env->from = h->env->to = alias;
254 mutt_default_save (p, sizeof (p), h);
255 h->env->from = h->env->to = NULL;
257 /* Avoid infinite recursion if the resulting folder starts with '@' */
268 m_strcpy(p, sizeof(p), NONULL(Inbox));
275 m_strcpy(p, sizeof(p), NONULL(Outbox));
282 if (*(s + 1) == '!') {
283 m_strcpy(p, sizeof(p), NONULL(LastFolder));
287 m_strcpy(p, sizeof(p), NONULL(Spoolfile));
295 m_strcpy(p, sizeof(p), NONULL(LastFolder));
302 m_strcpy(p, sizeof(p), NONULL(CurrentFolder));
314 if (rx && *p && !recurse) {
315 rx_sanitize_string (q, sizeof (q), p);
316 snprintf (tmp, sizeof (tmp), "%s%s", q, tail);
319 snprintf (tmp, sizeof (tmp), "%s%s", p, tail);
321 m_strcpy(s, slen, tmp);
328 /* move all the headers from extra not present in base into base */
329 void mutt_merge_envelopes(ENVELOPE* base, ENVELOPE** extra)
331 /* copies each existing element if necessary, and sets the element
332 * to NULL in the source so that envelope_delete doesn't leave us
333 * with dangling pointers. */
334 #define MOVE_ELEM(h) if (!base->h) { base->h = (*extra)->h; (*extra)->h = NULL; }
335 MOVE_ELEM(return_path);
342 MOVE_ELEM(mail_followup_to);
343 MOVE_ELEM(list_post);
344 MOVE_ELEM(message_id);
345 MOVE_ELEM(supersedes);
348 if (!base->refs_changed) {
349 MOVE_ELEM(references);
351 if (!base->irt_changed) {
352 MOVE_ELEM(in_reply_to);
354 /* real_subj is subordinate to subject */
355 if (!base->subject) {
356 base->subject = (*extra)->subject;
357 base->real_subj = (*extra)->real_subj;
358 (*extra)->subject = NULL;
359 (*extra)->real_subj = NULL;
361 /* spam and user headers should never be hashed, and the new envelope may
362 * have better values. Use new versions regardless. */
363 mutt_buffer_free (&base->spam);
364 string_list_wipe(&base->userhdrs);
369 envelope_delete(extra);
372 void mutt_mktemp (char *s)
375 snprintf (s, _POSIX_PATH_MAX, "%s/madmutt-%s-%d-%d-%d-%x%x", NONULL (Tempdir),
376 NONULL (Hostname), (int) getuid (), (int) getpid (), Counter++,
377 (unsigned int) rand(), (unsigned int) rand());
381 /* collapse the pathname using ~ or = when possible */
382 void mutt_pretty_mailbox (char *s)
388 scheme = url_check_scheme (s);
390 if (scheme == U_IMAP || scheme == U_IMAPS) {
391 imap_pretty_mailbox (s);
395 /* if s is an url, only collapse path component */
396 if (scheme != U_UNKNOWN) {
397 p = strchr (s, ':') + 1;
398 if (!strncmp (p, "//", 2))
399 q = strchr (p + 2, '/');
401 q = strchr (p, '\0');
405 /* first attempt to collapse the pathname */
407 if (*p == '/' && p[1] == '/') {
411 else if (p[0] == '/' && p[1] == '.' && p[2] == '/') {
420 if (m_strncmp(s, Maildir, (len = m_strlen(Maildir))) == 0 &&
423 memmove (s, s + len, m_strlen(s + len) + 1);
425 else if (m_strncmp(s, Homedir, (len = m_strlen(Homedir))) == 0 &&
428 memmove (s, s + len - 1, m_strlen(s + len - 1) + 1);
432 void mutt_pretty_size (char *s, ssize_t len, long n)
435 m_strcpy(s, len, "0K");
436 else if (n < 10189) /* 0.1K - 9.9K */
437 snprintf (s, len, "%3.1fK", (n < 103) ? 0.1 : n / 1024.0);
438 else if (n < 1023949) { /* 10K - 999K */
439 /* 51 is magic which causes 10189/10240 to be rounded up to 10 */
440 snprintf (s, len, "%ldK", (n + 51) / 1024);
442 else if (n < 10433332) /* 1.0M - 9.9M */
443 snprintf (s, len, "%3.1fM", n / 1048576.0);
446 /* (10433332 + 52428) / 1048576 = 10 */
447 snprintf (s, len, "%ldM", (n + 52428) / 1048576);
451 void mutt_expand_file_fmt(char *dest, ssize_t destlen,
452 const char *fmt, const char *src)
454 char tmp[LONG_STRING];
456 mutt_quote_filename(tmp, sizeof(tmp), src);
457 mutt_expand_fmt(dest, destlen, fmt, tmp);
460 void mutt_expand_fmt(char *dst, ssize_t dlen,
461 const char *fmt, const char *src)
466 while (*fmt && pos < dlen - 1) {
471 pos += m_strcpy(dst + pos, dlen - pos, src);
489 pos += m_strcpy(dst + pos, dlen - pos, " ");
490 pos += m_strcpy(dst + pos, dlen - pos, src);
494 /* return 0 on success, -1 on abort, 1 on error */
495 int mutt_check_overwrite (const char *attname, const char *path,
496 char *fname, ssize_t flen, int *append,
500 char tmp[_POSIX_PATH_MAX];
503 m_strcpy(fname, flen, path);
504 if (access (fname, F_OK) != 0)
506 if (stat (fname, &st) != 0)
508 if (S_ISDIR (st.st_mode)) {
510 switch (mutt_multi_choice
511 (_("File is a directory, save under it? [(y)es, (n)o, (a)ll]"),
514 m_strreplace(directory, fname);
529 mutt_yesorno (_("File is a directory, save under it?"),
531 return (rc == M_NO) ? 1 : -1;
533 if (!attname || !attname[0]) {
535 if (mutt_get_field (_("File under directory: "), tmp, sizeof (tmp),
536 M_FILE | M_CLEAR) != 0 || !tmp[0])
538 mutt_concat_path(fname, flen, path, tmp);
541 mutt_concat_path(fname, flen, path, mutt_basename(attname));
544 if (*append == 0 && access (fname, F_OK) == 0) {
545 switch (mutt_multi_choice
546 (_("File exists, (o)verwrite, (a)ppend, or (c)ancel?"), _("oac")))
554 *append = M_SAVE_APPEND;
556 case 1: /* overwrite */
557 *append = M_SAVE_OVERWRITE;
564 void mutt_save_path(char *d, ssize_t dsize, address_t *a)
566 if (a && a->mailbox) {
567 m_strcpy(d, dsize, a->mailbox);
569 if (!option(OPTSAVEADDRESS)) {
570 char *p = strpbrk(d, "%@");
580 void mutt_safe_path(char *s, ssize_t l, address_t *a)
582 mutt_save_path(s, l, a);
585 if (*s == '/' || ISSPACE(*s) || !isprint((unsigned char)*s))
591 void mutt_FormatString (char *dest, /* output buffer */
592 ssize_t destlen, /* output buffer len */
593 const char *src, /* template string */
594 format_t * callback, /* callback for processing */
595 unsigned long data, /* callback data */
597 { /* callback flags */
598 char prefix[SHORT_STRING], buf[LONG_STRING], *cp, *wptr = dest, ch;
599 char ifstring[SHORT_STRING], elsestring[SHORT_STRING];
600 ssize_t wlen, wid, count, col, len;
603 destlen--; /* save room for the terminal \0 */
604 wlen = (flags & M_FORMAT_ARROWCURSOR && option (OPTARROWCURSOR)) ? 3 : 0;
607 while (*src && wlen < destlen) {
618 flags |= M_FORMAT_OPTIONAL;
622 flags &= ~M_FORMAT_OPTIONAL;
624 /* eat the format string */
627 while (count < ssizeof (prefix) &&
628 (isdigit ((unsigned char) *src) || *src == '.' || *src == '-'))
637 break; /* bad format */
639 ch = *src++; /* save the character to switch on */
641 if (flags & M_FORMAT_OPTIONAL) {
643 break; /* bad format */
646 /* eat the `if' part of the string */
649 while (count < ssizeof (ifstring) && *src && *src != '?'
656 /* eat the `else' part of the string (optional) */
658 src++; /* skip the & */
661 while (count < ssizeof (elsestring) && *src && *src != '?') {
668 break; /* bad format */
670 src++; /* move past the trailing `?' */
673 /* handle generic cases first */
675 /* right justify to EOL */
676 ch = *src++; /* pad char */
677 /* calculate space left on line. if we've already written more data
678 than will fit on the line, ignore the rest of the line */
679 if (DrawFullLine || option (OPTSTATUSONTOP))
680 count = (COLS < destlen ? COLS : destlen);
682 count = ((COLS - SW) < destlen ? (COLS - SW) : destlen);
684 count -= col; /* how many columns left on this line */
685 mutt_FormatString (buf, sizeof (buf), src, callback, data, flags);
688 count -= wid; /* how many chars to pad */
689 memset (wptr, ch, count);
693 if (wid + wlen > destlen)
694 len = destlen - wlen;
697 memcpy (wptr, buf, len);
700 col += mutt_strwidth (buf);
702 break; /* skip rest of input */
704 else if (ch == '|') {
709 if (destlen > wlen) {
710 count = destlen - wlen;
711 memset (wptr, ch, count);
714 break; /* skip rest of input */
720 while (ch == '_' || ch == ':') {
729 /* use callback function to handle this case */
731 callback (buf, sizeof (buf), ch, src, prefix, ifstring, elsestring,
744 if ((len = m_strlen(buf)) + wlen > destlen)
745 len = (destlen - wlen > 0) ? (destlen - wlen) : 0;
747 memcpy (wptr, buf, len);
750 col += mutt_strwidth (buf);
753 else if (*src == '\\') {
782 unsigned int bar = strcspn(src, "%\\");
783 char *bar2 = p_dupstr(src, bar);
789 col += mutt_strwidth (bar2);
796 if (flags & M_FORMAT_MAKEPRINT) {
797 /* Make sure that the string is printable by changing all non-printable
798 chars to dots, or spaces for non-printable whitespace */
799 for (cp = dest; *cp; cp++)
800 if (!isprint(*cp) && !((flags & M_FORMAT_TREE) && (*cp <= M_TREE_MAX)))
801 *cp = isspace ((unsigned char) *cp) ? ' ' : '.';
806 /* returns 0 if OK to proceed, -1 to abort, 1 to retry */
807 int mutt_save_confirm (const char *s, struct stat *st)
809 char tmp[_POSIX_PATH_MAX];
814 magic = mx_get_magic (s);
816 if (magic == M_POP) {
817 mutt_error _("Can't save message to POP mailbox.");
823 if (magic == M_NNTP) {
824 mutt_error _("Can't save message to newsserver.");
830 if (magic > 0 && !mx_access (s, W_OK)) {
831 if (option (OPTCONFIRMAPPEND) &&
832 (!TrashPath || (m_strcmp(s, TrashPath) != 0))) {
833 /* if we're appending to the trash, there's no point in asking */
834 snprintf (tmp, sizeof (tmp), _("Append messages to %s?"), s);
835 if ((rc = mutt_yesorno (tmp, M_YES)) == M_NO)
842 if (stat (s, st) != -1) {
844 mutt_error (_("%s is not a mailbox!"), s);
854 if (errno == ENOENT) {
855 if (option (OPTCONFIRMCREATE)) {
856 snprintf (tmp, sizeof (tmp), _("Create %s?"), s);
857 if ((rc = mutt_yesorno (tmp, M_YES)) == M_NO)
870 CLEARLINE (LINES - 1);
874 void mutt_sleep (short s)
876 sleep(MAX(s, SleepTime));
879 /* Decrease a file's modification time by 1 second */
880 time_t mutt_decrease_mtime (const char *f, struct stat *st)
887 if (stat (f, &_st) == -1)
892 if ((mtime = st->st_mtime) == time (NULL)) {
895 utim.modtime = mtime;
902 /* sets mtime of 'to' to mtime of 'from' */
903 void mutt_set_mtime (const char* from, const char* to) {
907 if (stat (from, &st) != -1) {
908 utim.actime = st.st_mtime;
909 utim.modtime = st.st_mtime;
914 const char *mutt_make_version (int full)
916 static char vstring[STRING];
919 snprintf (vstring, sizeof (vstring),
920 "Madmutt/%s-r%s (based on Mutt 1.5.11)",
921 MUTT_VERSION, MUTT_REVISION);
923 snprintf (vstring, sizeof (vstring), "Madmutt/%s-%s",
924 MUTT_VERSION, MUTT_REVISION);
928 void mutt_free_spam_list (SPAM_LIST ** list)
936 *list = (*list)->next;
938 p_delete(&p->template);
943 int mutt_match_spam_list (const char *s, SPAM_LIST * l, char *text, int x)
945 static regmatch_t *pmatch = NULL;
946 static int nmatch = 0;
955 for (; l; l = l->next) {
956 /* If this pattern needs more matches, expand pmatch. */
957 if (l->nmatch > nmatch) {
958 p_realloc(&pmatch, l->nmatch);
962 /* Does this pattern match? */
963 if (regexec(l->rx->rx, s, l->nmatch, (regmatch_t *)pmatch, (int) 0) == 0)
965 /* Copy template into text, with substitutions. */
966 for (p = l->template; *p;) {
968 n = atoi (++p); /* find pmatch index */
969 while (isdigit ((unsigned char) *p))
970 ++p; /* skip subst token */
971 for (i = pmatch[n].rm_so; (i < pmatch[n].rm_eo) && (tlen < x); i++)
986 int mutt_cmp_header (const HEADER * h1, const HEADER * h2) {
988 if (h1->received != h2->received ||
989 h1->date_sent != h2->date_sent ||
990 h1->content->length != h2->content->length ||
991 h1->lines != h2->lines ||
992 h1->zhours != h2->zhours ||
993 h1->zminutes != h2->zminutes ||
994 h1->zoccident != h2->zoccident ||
995 h1->mime != h2->mime ||
996 !mutt_cmp_env (h1->env, h2->env) ||
997 !mutt_cmp_body (h1->content, h2->content))
1003 if (h1 == NULL && h2 == NULL)
1010 /* return 1 if address lists are strictly identical */
1011 int mutt_cmp_addr (const address_t * a, const address_t * b)
1014 if (m_strcmp(a->mailbox, b->mailbox) ||
1015 m_strcmp(a->personal, b->personal))
1027 int mutt_cmp_list (const string_list_t * a, const string_list_t * b)
1030 if (m_strcmp(a->data, b->data))
1042 int mutt_cmp_env (const ENVELOPE * e1, const ENVELOPE * e2)
1045 if (m_strcmp(e1->message_id, e2->message_id) ||
1046 m_strcmp(e1->subject, e2->subject) ||
1047 !mutt_cmp_list (e1->references, e2->references) ||
1048 !mutt_cmp_addr (e1->from, e2->from) ||
1049 !mutt_cmp_addr (e1->sender, e2->sender) ||
1050 !mutt_cmp_addr (e1->reply_to, e2->reply_to) ||
1051 !mutt_cmp_addr (e1->to, e2->to) ||
1052 !mutt_cmp_addr (e1->cc, e2->cc) ||
1053 !mutt_cmp_addr (e1->return_path, e2->return_path))
1059 if (e1 == NULL && e2 == NULL)
1066 int mutt_cmp_body (const BODY * b1, const BODY * b2)
1068 if (b1->type != b2->type ||
1069 b1->encoding != b2->encoding ||
1070 m_strcmp(b1->subtype, b2->subtype) ||
1071 m_strcmp(b1->description, b2->description) ||
1072 !parameter_equal(b1->parameter, b2->parameter) ||
1073 b1->length != b2->length)
1078 int mutt_extract_token(BUFFER *dest, BUFFER *tok, int flags)
1081 char qc = 0; /* quote char */
1084 /* reset the destination pointer to the beginning of the buffer */
1085 dest->dptr = dest->data;
1087 tok->dptr = vskipspaces(tok->dptr);
1088 while ((ch = *tok->dptr)) {
1090 if ((ISSPACE(ch) && !(flags & M_TOKEN_SPACE))
1091 || (ch == '#' && !(flags & M_TOKEN_COMMENT))
1092 || (ch == '=' && (flags & M_TOKEN_EQUAL))
1093 || (ch == ';' && !(flags & M_TOKEN_SEMICOLON))
1094 || ((flags & M_TOKEN_PATTERN) && strchr("~=!|", ch)))
1103 qc = 0; /* end of quote */
1105 if (!qc && (ch == '\'' || ch == '"') && !(flags & M_TOKEN_QUOTE)) {
1108 if (ch == '\\' && qc != '\'') {
1110 return -1; /* premature end of token */
1112 switch (ch = *tok->dptr++) {
1116 return -1; /* premature end of token */
1117 mutt_buffer_addch(dest,
1118 (ascii_toupper(*tok->dptr) - 'A' + 1) & 0x7f);
1122 mutt_buffer_addch(dest, '\r');
1125 mutt_buffer_addch(dest, '\n');
1128 mutt_buffer_addch(dest, '\t');
1131 mutt_buffer_addch(dest, '\f');
1134 mutt_buffer_addch(dest, '\033');
1137 if (isdigit((unsigned char)ch)
1138 && isdigit((unsigned char)*tok->dptr)
1139 && isdigit((unsigned char)*(tok->dptr + 1)))
1141 mutt_buffer_addch(dest, (ch << 6) + (*tok->dptr << 3) +
1142 *(tok->dptr + 1) - 3504);
1145 mutt_buffer_addch(dest, ch);
1149 if (ch == '^' && (flags & M_TOKEN_CONDENSE)) {
1151 return -1; /* premature end of token */
1154 mutt_buffer_addch(dest, ch);
1157 mutt_buffer_addch(dest, '\033');
1159 if (isalpha((unsigned char)ch)) {
1160 mutt_buffer_addch(dest, ascii_toupper(ch) - 'A' + 1);
1162 mutt_buffer_addch(dest, '^');
1163 mutt_buffer_addch(dest, ch);
1166 if (ch == '`' && (!qc || qc == '"')) {
1176 if ((pc = strpbrk(pc, "\\`"))) {
1177 /* skip any quoted chars */
1181 } while (pc && *pc != '`');
1186 cmd = p_dupstr(tok->dptr, pc - tok->dptr);
1187 if ((pid = mutt_create_filter(cmd, NULL, &fp, NULL)) < 0) {
1197 expn.data = mutt_read_line(NULL, &expn.dsize, fp, &line);
1199 mutt_wait_filter(pid);
1201 /* if we got output, make a new string consiting of the shell ouptput
1202 plus whatever else was left on the original line */
1203 /* BUT: If this is inside a quoted string, directly add output to
1205 if (expn.data && qc) {
1206 mutt_buffer_addstr(dest, expn.data);
1207 p_delete(&expn.data);
1210 expnlen = m_strlen(expn.data);
1211 tok->dsize = expnlen + m_strlen(tok->dptr) + 1;
1212 ptr = xmalloc(tok->dsize);
1213 memcpy(ptr, expn.data, expnlen);
1214 strcpy(ptr + expnlen, tok->dptr); /* __STRCPY_CHECKED__ */
1216 p_delete(&tok->data);
1219 tok->destroy = 1; /* mark that the caller should destroy this data */
1221 p_delete(&expn.data);
1224 if (ch == '$' && (!qc || qc == '"')
1225 && (*tok->dptr == '{' || isalpha((unsigned char)*tok->dptr)))
1227 char *env = NULL, *var = NULL;
1229 if (*tok->dptr == '{') {
1231 if ((pc = strchr (tok->dptr, '}'))) {
1232 var = p_dupstr(tok->dptr, pc - tok->dptr);
1236 for (pc = tok->dptr; isalnum((unsigned char)*pc) || *pc == '_';
1238 var = p_dupstr(tok->dptr, pc - tok->dptr);
1243 if ((env = getenv (var))
1244 || (mutt_option_value (var, tmp, sizeof (tmp)) && (env = tmp)))
1246 mutt_buffer_addstr (dest, env);
1251 mutt_buffer_addch(dest, ch);
1254 mutt_buffer_addch(dest, 0); /* terminate the string */
1255 tok->dptr = vskipspaces(tok->dptr);