summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2017-07-07 13:50:57 +0300
committerSergey Poznyakoff <gray@gnu.org>2017-07-07 13:50:57 +0300
commit3360c4365757404cabb34895b3b77851d0266ce4 (patch)
treed794c9d9267eb5ee044fd450c87cf48a147a63cb
parent8d8920958af07a11f247683949934f59525d7abd (diff)
downloadmailutils-3360c4365757404cabb34895b3b77851d0266ce4.tar.gz
mailutils-3360c4365757404cabb34895b3b77851d0266ce4.tar.bz2
Simplify mh_fvm_run calling sequence.
The commit 6b16ba19 (in its changes to mh/mh_format.c) inadvertently broke the operaton of inc on folders with gaps in sequence (UID) numbering. It turns out that the msgno argument to mh_fvm_run (and msgno member in struct mh_fvm) can be disposed of. If the caller wants to supply an explicit UID number of the messagem, it should use mu_message_set_uid. * mh/mh.h (mh_fvm_run): Take only two arguments: fvm and message. * mh/mh_format.h (mh_fvm) <msgno>: Remove. * mh/fmtcheck.c (run): Set the uid accessor on the created message. * mh/mh_format.c (mh_format_str): Likewise. (builtin_msg, builtin_cur): Always call mh_message_number. * mh/inc.c: Update calls to mh_fvm_run * mh/repl.c: Likewise. * mh/scan.c: Likewise. * mh/sortm.c: Likewise. * mh/tests/inc.at: Check whether inc on folders with gaps in message UIDs produces the correct output.
-rw-r--r--mh/fmtcheck.c13
-rw-r--r--mh/inc.c4
-rw-r--r--mh/mh.h2
-rw-r--r--mh/mh_format.c27
-rw-r--r--mh/mh_format.h1
-rw-r--r--mh/repl.c4
-rw-r--r--mh/scan.c8
-rw-r--r--mh/sortm.c2
-rw-r--r--mh/tests/inc.at13
9 files changed, 52 insertions, 22 deletions
diff --git a/mh/fmtcheck.c b/mh/fmtcheck.c
index b0d7d37e2..b2349aa7a 100644
--- a/mh/fmtcheck.c
+++ b/mh/fmtcheck.c
@@ -81,16 +81,27 @@ static struct mu_option options[] = {
MU_OPTION_END
};
+static int
+msg_uid (mu_message_t msg MU_ARG_UNUSED, size_t *ret)
+{
+ if (!ret)
+ return MU_ERR_OUT_PTR_NULL;
+ *ret = msgno;
+ return 0;
+}
+
static void
run (void)
{
mu_message_t msg = mh_file_to_message (NULL, input_file);
mh_fvm_t fvm;
+ MU_ASSERT (mu_message_set_uid (msg, msg_uid, mu_message_get_owner (msg)));
+
mh_fvm_create (&fvm, MH_FMT_FORCENL);
mh_fvm_set_width (fvm, width ? width : mh_width ());
mh_fvm_set_format (fvm, format);
- mh_fvm_run (fvm, msg, msgno);
+ mh_fvm_run (fvm, msg);
mh_fvm_destroy (&fvm);
}
diff --git a/mh/inc.c b/mh/inc.c
index 859ba8232..27678c6ad 100644
--- a/mh/inc.c
+++ b/mh/inc.c
@@ -132,11 +132,11 @@ list_message (mu_mailbox_t mbox, size_t msgno)
mu_message_t msg;
mu_mailbox_get_message (mbox, msgno, &msg);
- mh_fvm_run (fvm, msg, msgno);
+ mh_fvm_run (fvm, msg);
if (audit_stream)
{
mh_fvm_set_output (fvm, audit_stream);
- mh_fvm_run (fvm, msg, msgno);
+ mh_fvm_run (fvm, msg);
mh_fvm_set_output (fvm, mu_strout);
}
}
diff --git a/mh/mh.h b/mh/mh.h
index c1d8ee85a..400affac8 100644
--- a/mh/mh.h
+++ b/mh/mh.h
@@ -177,7 +177,7 @@ void mh_fvm_set_output (mh_fvm_t fvm, mu_stream_t str);
void mh_fvm_set_width (mh_fvm_t fvm, size_t width);
void mh_fvm_set_format (mh_fvm_t fvm, mh_format_t fmt);
-void mh_fvm_run (mh_fvm_t fvm, mu_message_t msg, size_t msgno);
+void mh_fvm_run (mh_fvm_t fvm, mu_message_t msg);
int mh_format_str (mh_format_t fmt, char *str, size_t width, char **pret);
diff --git a/mh/mh_format.c b/mh/mh_format.c
index 05d6d5511..ee0f87378 100644
--- a/mh/mh_format.c
+++ b/mh/mh_format.c
@@ -474,10 +474,9 @@ addrlist_destroy (mu_list_t *list)
/* Execute pre-compiled format on message msg with number msgno.
*/
void
-mh_fvm_run (mh_fvm_t mach, mu_message_t msg, size_t msgno)
+mh_fvm_run (mh_fvm_t mach, mu_message_t msg)
{
mach->message = msg;
- mach->msgno = msgno;
reset_fmt_defaults (mach);
mu_list_clear (mach->addrlist);
@@ -656,6 +655,15 @@ mh_fvm_run (mh_fvm_t mach, mu_message_t msg, size_t msgno)
put_string (mach, "\n", 1);
}
+static int
+msg_uid_1 (mu_message_t msg MU_ARG_UNUSED, size_t *ret)
+{
+ if (!ret)
+ return MU_ERR_OUT_PTR_NULL;
+ *ret = 1;
+ return 0;
+}
+
int
mh_format_str (mh_format_t fmt, char *str, size_t width, char **pstr)
{
@@ -672,12 +680,13 @@ mh_format_str (mh_format_t fmt, char *str, size_t width, char **pstr)
MU_ASSERT (mu_message_get_header (msg, &hdr));
MU_ASSERT (mu_header_set_value (hdr, "text", str, 1));
MU_ASSERT (mu_memory_stream_create (&outstr, MU_STREAM_RDWR));
-
+ MU_ASSERT (mu_message_set_uid (msg, msg_uid_1, NULL));
+
mh_fvm_create (&fvm, 0);
mh_fvm_set_output (fvm, outstr);
mh_fvm_set_width (fvm, width);
mh_fvm_set_format (fvm, fmt);
- mh_fvm_run (fvm, msg, 1);
+ mh_fvm_run (fvm, msg);
mh_fvm_destroy (&fvm);
MU_ASSERT (mu_stream_size (outstr, &size));
@@ -705,16 +714,15 @@ builtin_not_implemented (char *name)
static void
builtin_msg (struct mh_fvm *mach)
{
- size_t msgno = mach->msgno;
- if (msgno == 0)
- mh_message_number (mach->message, &msgno);
+ size_t msgno;
+ mh_message_number (mach->message, &msgno);
mach->num[R_REG] = msgno;
}
static void
builtin_cur (struct mh_fvm *mach)
{
- size_t msgno = mach->msgno;
+ size_t msgno;
size_t cur;
int rc;
mu_mailbox_t mbox;
@@ -725,8 +733,7 @@ builtin_cur (struct mh_fvm *mach)
mu_diag_funcall (MU_DIAG_ERROR, "mu_message_get_mailbox", NULL, rc);
exit (1);
}
- if (msgno == 0)
- mh_message_number (mach->message, &msgno);
+ mh_message_number (mach->message, &msgno);
mh_mailbox_get_cur (mbox, &cur); /* FIXME: Cache this */
mach->num[R_REG] = msgno == cur;
}
diff --git a/mh/mh_format.h b/mh/mh_format.h
index fd466d1fe..07fc6feb2 100644
--- a/mh/mh_format.h
+++ b/mh/mh_format.h
@@ -175,7 +175,6 @@ struct mh_fvm
int fmtflags; /* Current formatting flags */
mu_message_t message; /* Current message */
- size_t msgno; /* Its number */
};
mh_builtin_t *mh_lookup_builtin (char *name, size_t len);
diff --git a/mh/repl.c b/mh/repl.c
index ec2711881..a39ec7094 100644
--- a/mh/repl.c
+++ b/mh/repl.c
@@ -247,11 +247,11 @@ make_draft (mu_mailbox_t mbox, int disp, struct mh_whatnow_env *wh)
mu_message_get_header (tmp_msg, &hdr);
text = mu_opool_finish (fcc_pool, NULL);
mu_header_set_value (hdr, MU_HEADER_FCC, text, 1);
- mh_fvm_run (fvm, tmp_msg, msgno);
+ mh_fvm_run (fvm, tmp_msg);
mu_message_destroy (&tmp_msg, NULL);
}
else
- mh_fvm_run (fvm, msg, msgno);
+ mh_fvm_run (fvm, msg);
if (mhl_filter)
{
diff --git a/mh/scan.c b/mh/scan.c
index 8d1e677cc..7ff2519ef 100644
--- a/mh/scan.c
+++ b/mh/scan.c
@@ -68,9 +68,10 @@ static void print_header (mu_mailbox_t mbox);
static void clear_screen (void);
static int
-list_message (size_t num, mu_message_t msg, void *data)
+list_message (size_t num MU_ARG_UNUSED, mu_message_t msg,
+ void *data MU_ARG_UNUSED)
{
- mh_fvm_run (fvm, msg, num);
+ mh_fvm_run (fvm, msg);
return 0;
}
@@ -88,8 +89,7 @@ action (mu_observer_t o, size_t type, void *data, void *action_data)
mbox = mu_observer_get_owner (o);
counter++;
mu_mailbox_get_message (mbox, counter, &msg);
- mh_message_number (msg, &num);
- mh_fvm_run (fvm, msg, num);
+ mh_fvm_run (fvm, msg);
}
return 0;
}
diff --git a/mh/sortm.c b/mh/sortm.c
index 140294ad9..c53e64ff5 100644
--- a/mh/sortm.c
+++ b/mh/sortm.c
@@ -443,7 +443,7 @@ list_message (size_t num)
{
mu_message_t msg = NULL;
mu_mailbox_get_message (mbox, num, &msg);
- mh_fvm_run (fvm, msg, num);
+ mh_fvm_run (fvm, msg);
}
void
diff --git a/mh/tests/inc.at b/mh/tests/inc.at
index d696db4fc..248655c07 100644
--- a/mh/tests/inc.at
+++ b/mh/tests/inc.at
@@ -87,6 +87,19 @@ grep ^cur: Mail/inbox/.mh_sequences
cur: 1
])
+MH_CHECK([sparse numbering],[inc05 inc-sparse],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+mv Mail/inbox/5 Mail/inbox/20
+MUT_MBCOPY([$abs_top_srcdir/testsuite/spool/mbox1])
+inc -changecur -file ./mbox1 | sed 's/ *$//'
+],
+[0],
+[ 21+ 12/28 Foo Bar Jabberwocky<<`Twas brillig, and the slithy toves
+ 22 12/28 Bar Re: Jabberwocky<<It seems very pretty, but it's
+ 23 07/13 Sergey Poznyakoff Simple MIME<<------- =_aaaaaaaaaa0 Content-Type:
+ 24 07/13 Sergey Poznyakoff Nested MIME<<------- =_aaaaaaaaaa0 Content-Type:
+ 25 07/13 Sergey Poznyakoff Empty MIME Parts<<------- =_aaaaaaaaaa0 Content-
+])
m4_popdef[MH_KEYWORDS])
# End of inc.at

Return to:

Send suggestions and report system problems to the System administrator.