char *inbox = "Inbox"; /* profile entry name to specify the default folder */
char *curfolder = "Current-Folder";
-/* name of current message "sequence" */
-char *current = "cur";
-
+/* predefined sequences */
char *seq_all = "a";
char *seq_beyond = "b"; /* the previous `new' sequence */
char *seq_cur = "c";
#define set_selected(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] |= SELECTED)
#define is_select_empty(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] & SELECT_EMPTY)
-#define set_select_empty(mp,msgnum) \
- ((mp)->msgstats[(msgnum) - mp->lowoff] |= SELECT_EMPTY)
+#define set_select_empty(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] |= SELECT_EMPTY)
#define is_unseen(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] & SELECT_UNSEEN)
#define unset_unseen(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] &= ~SELECT_UNSEEN)
extern char *components;
extern char *context;
extern char *curfolder;
-extern char *current;
extern char *defaulteditor;
extern char *defaultfolder;
extern char *digestcomps;
mp->lowmsg = 1;
mp->hghmsg = hole - 1;
- /* update the "cur" sequence */
- if (newcurrent != 0)
+ if (newcurrent)
seq_setcur(mp, newcurrent);
return 0;
#define FIRST 1
#define LAST 2
-#define getnew(mp) (mp->hghmsg + 1)
+#define getnew(mp) ((mp)->hghmsg + 1)
-static int convdir; /* convert direction */
-static char *delimp;
+static int convdir; /* convert direction */
+static char *delimp; /* delimiter pointer */
/*
** static prototypes
found = 0;
/*
- ** Check for special "new" sequence, which
+ ** Check for special beyond sequence, which
** is valid only if ALLOW_NEW is set.
*/
- if ((mp->msgflags & ALLOW_NEW) && !strcmp(cp, "new")) {
+ if ((mp->msgflags & ALLOW_NEW) && !strcmp(cp, seq_beyond)) {
if ((err = first = getnew(mp)) <= 0)
goto badmsg;
else
goto single;
}
- if (!strcmp(cp, "all"))
- cp = "first-last";
+ if (!strcmp(cp, seq_all))
+ cp = concat(seq_first, "-", seq_last, NULL);
if ((err = first = m_conv(mp, cp, FIRST)) <= 0)
goto badmsg;
*/
if (mp->msgflags & ALLOW_NEW) {
set_select_empty(mp, first);
- } else {
- if (first > mp->hghmsg
- || first < mp->lowmsg
- || !(does_exist(mp, first))) {
- if (!strcmp(name, "cur"))
- advise(NULL, "no %s message", name);
- else
- advise(NULL, "message %d doesn't exist", first);
- return 0;
- }
+ } else if (first > mp->hghmsg || first < mp->lowmsg
+ || !does_exist(mp, first)) {
+ if (!strcmp(name, seq_cur))
+ advise(NULL, "no %s message", name);
+ else
+ advise(NULL, "message %d doesn't exist",
+ first);
+ return 0;
}
last = first; /* range of 1 */
}
/*
** Convert the various message names to
** their numeric values.
+** (`42' being an arbitrary number)
**
-** n (integer)
+** 42
** prev
** next
** first
*bp++ = '\0';
delimp = cp;
- if (!strcmp(buf, "first"))
+ if (!strcmp(buf, seq_first))
return (mp->hghmsg || !(mp->msgflags & ALLOW_NEW)
? mp->lowmsg : BADMSG);
- if (!strcmp(buf, "last")) {
+ if (!strcmp(buf, seq_last)) {
convdir = -1;
return (mp->hghmsg || !(mp->msgflags & ALLOW_NEW) ? mp->hghmsg : BADMSG);
}
- if (!strcmp(buf, "cur"))
+ if (!strcmp(buf, seq_cur))
return (mp->curmsg > 0 ? mp->curmsg : BADMSG);
- if (!strcmp(buf, "prev")) {
+ if (!strcmp(buf, seq_prev)) {
convdir = -1;
for (i = (mp->curmsg <= mp->hghmsg) ? mp->curmsg - 1 : mp->hghmsg;
i >= mp->lowmsg; i--) {
return BADMSG;
}
- if (!strcmp(buf, "next")) {
+ if (!strcmp(buf, seq_next)) {
for (i = (mp->curmsg >= mp->lowmsg) ? mp->curmsg + 1 : mp->lowmsg;
i <= mp->hghmsg; i++) {
if (does_exist(mp, i))
/*
** Handle user defined sequences.
** They can take the following forms:
+** (`42' being an arbitrary number)
**
** seq
** seq:prev
** seq:next
** seq:first
** seq:last
-** seq:+n
-** seq:-n
-** seq:n
+** seq:+42
+** seq:-42
+** seq:42
*/
-
static int
attr(struct msgs *mp, char *cp)
{
int range = 0; /* no range */
int first = 0;
- /* hack for "cur-name", "cur-n", etc. */
- if (!strcmp(cp, "cur"))
+ /* hack for "c-name", "c-42", etc. */
+ if (!strcmp(cp, seq_cur))
return 0;
- if (isprefix("cur:", cp)) /* this code need to be rewritten... */
+ /* "c:..." -- this code need to be rewritten... */
+ if (strncmp(seq_cur, cp, strlen(seq_cur))==0 &&
+ cp[strlen(seq_cur)] == ':') {
return 0;
+ }
/* Check for sequence negation */
if (!(dp = context_find(nsequence))) {
** seq:last
*/
if (isalpha(*dp)) {
- if (!strcmp(dp, "prev")) {
+ if (!strcmp(dp, seq_prev)) {
convdir = -1;
first = (mp->curmsg > 0) && (mp->curmsg <= mp->hghmsg)
? mp->curmsg - 1 : mp->hghmsg;
- } else if (!strcmp(dp, "next")) {
+ } else if (!strcmp(dp, seq_next)) {
convdir = 1;
first = (mp->curmsg >= mp->lowmsg)
? mp->curmsg + 1 : mp->lowmsg;
- } else if (!strcmp(dp, "first")) {
+ } else if (!strcmp(dp, seq_first)) {
convdir = 1;
- } else if (!strcmp(dp, "last")) {
+ } else if (!strcmp(dp, seq_last)) {
convdir = -1;
} else
return BADLST;
} else {
/*
- ** seq:n (or)
- ** seq:+n (or)
- ** seq:-n
+ ** seq:42 (or)
+ ** seq:+42 (or)
+ ** seq:-42
*/
if (*dp == '+')
dp++;
/*
-** `which' should either be "cur" to use the current draft
-** or "new" to start with a new draft.
+** `which' should either be the cur sequence to use the current draft
+** or the beyond sequence to start with a new draft.
*/
char *
m_draft(char *which)
/*
** Make sure we have enough message status space for all
- ** the message numbers from 1 to "new", since we might
+ ** the message numbers from 1 to one beyond last, since we might
** select an empty slot. If we add more space at the
** end, go ahead and add 10 additional slots.
*/
/*
** The draft message name to return is defined by `which'.
- ** Usually it is "cur" (for the current draft) or "new"
+ ** Usually it is seq_cur (for the current draft) or seq_beyond
** (to start a new draft).
*/
if (!m_convert(mp, which))
return 0;
/*
- ** We keep mp->curmsg and "cur" sequence in sync.
+ ** We keep mp->curmsg and cur sequence in sync.
** See seq_list() and seq_init().
*/
- if (!strcmp(current,cp))
+ if (!strcmp(seq_cur, cp))
mp->curmsg = mp->hghsel;
/*
return 0;
/*
- ** keep mp->curmsg and msgattrs["cur"] in sync - see seq_list()
+ ** keep mp->curmsg and msgattrs[] of seq_cur in sync - see seq_list()
*/
- if (!strcmp(current,cp))
+ if (!strcmp(seq_cur, cp))
mp->curmsg = msgnum;
/*
}
/*
- ** Special processing for "cur" sequence. We assume that the
- ** "cur" sequence and mp->curmsg are in sync (see seq_add.c).
+ ** Special processing for the cur sequence. We assume that the
+ ** cur sequence and mp->curmsg are in sync (see seq_add.c).
** This is returned, even if message doesn't exist or the
** folder is empty.
*/
- if (!strcmp(current, seqname)) {
+ if (!strcmp(seq_cur, seqname)) {
if (mp->curmsg) {
sprintf(buffer, "%s", m_name(mp->curmsg));
return (buffer);
/*
-** seq_nameok.c -- check if a sequence name is ok
+** seq_nameok.c -- check if a name is ok for a user-defined sequence
**
** This code is Copyright (c) 2002, by the authors of nmh. See the
** COPYRIGHT file in the root directory of the nmh distribution for
#include <h/mh.h>
+/*
+** returns true if it is a valid name for a user-defined sequence
+*/
int
seq_nameok(unsigned char *s)
{
/*
** Make sure sequence name doesn't clash with one
** of the `reserved' sequence names.
+ ** Note: Accept `cur' here! But why is it treated special? --meillo
*/
- if (!(strcmp(s, "new") &&
- strcmp(s, "all") &&
- strcmp(s, "first") &&
- strcmp(s, "last") &&
- strcmp(s, "prev") &&
- strcmp(s, "next"))) {
- advise(NULL, "illegal sequence name: %s", s);
+ if (strcmp(s, seq_first)==0 || strcmp(s, seq_last)==0 ||
+ strcmp(s, seq_prev)==0 || strcmp(s, seq_next)==0 ||
+ strcmp(s, seq_all)==0 || strcmp(s, seq_beyond)==0) {
+ advise(NULL, "collision with reserved sequence name: `%s'", s);
return 0;
}
** an alphabetic character ...
*/
if (!isalpha(*s)) {
- advise(NULL, "illegal sequence name: %s", s);
+ advise(NULL, "sequence name must start with a letter: %s", s);
return 0;
}
/*
** and can be followed by zero or more alphanumeric characters
*/
- for (pp = s + 1; *pp; pp++)
+ for (pp = s+1; *pp; pp++) {
if (!isalnum(*pp)) {
- advise(NULL, "illegal sequence name: %s", s);
+ advise(NULL, "sequence name must only contain "
+ "letters and digits: %s", s);
return 0;
}
+ }
return 1;
}
{
/*
** Initialize the list of sequence names. Go ahead and
- ** add the "cur" sequence to the list of sequences.
+ ** add the cur sequence to the list of sequences.
*/
- mp->msgattrs[0] = getcpy(current);
+ mp->msgattrs[0] = getcpy(seq_cur);
mp->msgattrs[1] = NULL;
make_all_public(mp); /* initially, make all public */
char *cp, **ap;
/*
- ** Check if this is "cur" sequence,
+ ** Check if this is the cur sequence,
** so we can do some special things.
*/
- is_current = !strcmp(current, name);
+ is_current = !strcmp(seq_cur, name);
/*
** Search for this sequence name to see if we've seen
k = cp ? m_atoi(cp) : j;
/*
- ** Keep mp->curmsg and "cur" sequence in synch. Unlike
+ ** Keep mp->curmsg and cur sequence in sync. Unlike
** other sequences, this message doesn't need to exist.
** Think about the series of command (rmm; next) to
** understand why this can be the case. But if it does
/*
-** seq_setcur.c -- set the current message ("cur" sequence) for a folder
+** seq_setcur.c -- set the current message (cur sequence) for a folder
**
** This code is Copyright (c) 2002, by the authors of nmh. See the
** COPYRIGHT file in the root directory of the nmh distribution for
void
seq_setcur(struct msgs *mp, int msgnum)
{
- /*
- ** Just call seq_addmsg() to update the
- ** "cur" sequence.
- */
- seq_addmsg(mp, current, msgnum, -1, 1);
+ /* Just call seq_addmsg() to update the cur sequence. */
+ seq_addmsg(mp, seq_cur, msgnum, -1, 1);
}
#endif /* UCI */
if (!msgs.size)
- app_msgarg(&msgs, "cur");
+ app_msgarg(&msgs, seq_cur);
if (!folder)
folder = getcurfol();
maildir = toabsdir(folder);
}
if (!msgp)
- msgs[msgp++] = "cur";
+ msgs[msgp++] = seq_cur;
if (!folder)
folder = getcurfol();
maildir = toabsdir(folder);
** Take a message as the "form" for the new message.
*/
if (!msg)
- msg = "cur";
+ msg = seq_cur;
if (!folder)
folder = getcurfol();
maildir = toabsdir(folder);
in = open_form(&form, components);
try_it_again:
- strncpy(drft, m_draft(use ? (msg?msg:"cur") : "new"), sizeof(drft));
+ strncpy(drft, m_draft(use ? (msg?msg:seq_cur) : seq_beyond),
+ sizeof(drft));
/*
** Check if we have an existing draft
in = open_form(&form, distcomps);
- strncpy(drft, m_draft("new"), sizeof(drft));
+ strncpy(drft, m_draft(seq_beyond), sizeof(drft));
if ((out = creat(drft, m_gmprot())) == NOTOK)
adios(drft, "unable to create");
** Dist a message
*/
if (!msg)
- msg = "cur";
+ msg = seq_cur;
if (!folder)
folder = getcurfol();
maildir = toabsdir(folder);
char atrcur[BUFSIZ];
register struct node *np;
- snprintf(atrcur, sizeof(atrcur), "atr-%s-", current);
+ snprintf(atrcur, sizeof(atrcur), "atr-%s-", seq_cur);
atrlen = strlen(atrcur);
for (np = m_defs; np; np = np->n_next)
char atrcur[BUFSIZ];
register struct node *np;
- snprintf(atrcur, sizeof(atrcur), "atr-%s-", current);
+ snprintf(atrcur, sizeof(atrcur), "atr-%s-", seq_cur);
atrlen = strlen(atrcur);
for (np = m_defs; np; np = np->n_next)
#ifdef MHE
strncpy(drft, buildsw ? toabsdir("draft")
- : m_draft("new"), sizeof(drft));
+ : m_draft(seq_beyond), sizeof(drft));
#else
- strncpy(drft, m_draft("new"), sizeof(drft));
+ strncpy(drft, m_draft(seq_beyond), sizeof(drft));
#endif /* MHE */
if (file) {
** Forwarding a message.
*/
if (!msgp)
- msgs[msgp++] = "cur";
+ msgs[msgp++] = seq_cur;
if (!folder)
folder = getcurfol();
maildir = toabsdir(folder);
}
if (!msgs.size)
- app_msgarg(&msgs, listsw ? "all" :"cur");
+ app_msgarg(&msgs, listsw ? seq_all : seq_cur);
if (!folder)
folder = getcurfol();
maildir = toabsdir(folder);
ap = brkstring(ci->ci_magic, " ", "\n");
copyip(ap, arguments, MAXARGS);
} else {
- arguments[0] = "cur";
+ arguments[0] = seq_cur;
arguments[1] = NULL;
}
folder = NULL;
** message(s) are coming from a folder
*/
if (!msgs.size)
- app_msgarg(&msgs, "cur");
+ app_msgarg(&msgs, seq_cur);
if (!folder)
folder = getcurfol();
maildir = toabsdir(folder);
/*
** We need to make sure there is message status space
- ** for all the message numbers from 1 to "new" since
+ ** for all the message numbers from 1 to one beyond last since
** mhpath can select empty slots. If we are adding
** space at the end, we go ahead and add 10 slots.
*/
** message(s) are coming from a folder
*/
if (!msgs.size)
- app_msgarg(&msgs, "cur");
+ app_msgarg(&msgs, seq_cur);
if (!folder)
folder = getcurfol();
maildir = toabsdir(folder);
** message(s) are coming from a folder
*/
if (!msgs.size)
- app_msgarg(&msgs, "cur");
+ app_msgarg(&msgs, seq_cur);
if (!folder)
folder = getcurfol();
maildir = toabsdir(folder);
** message(s) are coming from a folder
*/
if (!msgs.size)
- app_msgarg(&msgs, "cur");
+ app_msgarg(&msgs, seq_cur);
if (!folder)
folder = getcurfol();
maildir = toabsdir(folder);
/* default is to pack whole folder */
if (!msgs.size)
- app_msgarg(&msgs, "all");
+ app_msgarg(&msgs, seq_all);
if (!folder)
folder = getcurfol();
** then search the whole folder.
*/
if (!msgs.size)
- app_msgarg(&msgs, "all");
+ app_msgarg(&msgs, seq_all);
if (!folder)
folder = getcurfol();
}
if (!msgs.size)
- app_msgarg(&msgs, "cur");
+ app_msgarg(&msgs, seq_cur);
if (!folder)
folder = getcurfol();
strncpy(maildir, toabsdir(folder), sizeof(maildir));
#ifdef MHE
strncpy(drft, buildsw ? toabsdir("reply")
- : m_draft("new"), sizeof(drft));
+ : m_draft(seq_beyond), sizeof(drft));
#else
- strncpy(drft, m_draft("new"), sizeof(drft));
+ strncpy(drft, m_draft(seq_beyond), sizeof(drft));
#endif /* MHE */
if (file) {
** We are replying to a message.
*/
if (!msg)
- msg = "cur";
+ msg = seq_cur;
if (!folder)
folder = getcurfol();
maildir = toabsdir(folder);
break; /* fall otherwise */
case NOTOK:
- snprintf(cur, sizeof(cur), "atr-%s-%s",
- current, toabsdir(folder));
+ snprintf(cur, sizeof(cur), "atr-%s-%s", seq_cur,
+ toabsdir(folder));
if (!context_del(cur)) {
printf("[+%s de-referenced]\n", folder);
return OK;
}
if (!msgs.size)
- app_msgarg(&msgs, "cur");
+ app_msgarg(&msgs, seq_cur);
if (!folder)
folder = getcurfol();
maildir = toabsdir(folder);
*/
if (!msgs.size)
- app_msgarg(&msgs, "all");
+ app_msgarg(&msgs, seq_all);
if (!folder)
folder = getcurfol();
maildir = toabsdir(folder);
}
if (!msgp)
- msgs[msgp++] = "cur";
+ msgs[msgp++] = seq_cur;
maildir = toabsdir(draftfolder);
if (chdir(maildir) == NOTOK)
if (!msgp) {
switch (mode) {
case NEXT:
- msgs[msgp++] = "next";
+ msgs[msgp++] = seq_next;
break;
case PREV:
- msgs[msgp++] = "prev";
+ msgs[msgp++] = seq_prev;
break;
default:
- msgs[msgp++] = "cur";
+ msgs[msgp++] = seq_cur;
break;
}
}
}
if (!msgs.size)
- app_msgarg(&msgs, "all");
+ app_msgarg(&msgs, seq_all);
if (!datesw)
datesw = "date";
if (!folder)
}
if ((drft == NULL && (drft = getenv("mhdraft")) == NULL) || *drft == 0)
- drft = getcpy(m_draft("cur"));
+ drft = getcpy(m_draft(seq_cur));
msgnam = (cp = getenv("mhaltmsg")) && *cp ? getcpy(cp) : NULL;