[RFC PATCH 04/13] Replace remaining places where fopen occurs
Ethan Glasser-Camp
glasse at cs.rpi.edu
Wed Feb 15 14:01:57 PST 2012
From: Ethan Glasser-Camp <ethan at betacantrips.com>
Because mail might no longer be on disk, other uses of fopen(2) need
to be replaced with calls to notmuch_mailstore_open. This isn't all of
them, but these are the ones that involve touching the API in a lot of
different places.
This commit updates mime_node_open, show_message_body, and a couple
random calls in the commands notmuch show, notmuch reply,
Signed-off-by: Ethan Glasser-Camp <ethan at betacantrips.com>
---
mime-node.c | 3 ++-
notmuch-client.h | 2 ++
notmuch-reply.c | 2 +-
notmuch-show.c | 9 +++++----
show-message.c | 3 ++-
5 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/mime-node.c b/mime-node.c
index d6b4506..856fc3b 100644
--- a/mime-node.c
+++ b/mime-node.c
@@ -61,6 +61,7 @@ _mime_node_context_free (mime_node_context_t *res)
notmuch_status_t
mime_node_open (const void *ctx, notmuch_message_t *message,
+ notmuch_mailstore_t *mailstore,
#ifdef GMIME_ATLEAST_26
GMimeCryptoContext *cryptoctx,
#else
@@ -89,7 +90,7 @@ mime_node_open (const void *ctx, notmuch_message_t *message,
}
talloc_set_destructor (mctx, _mime_node_context_free);
- mctx->file = fopen (filename, "r");
+ mctx->file = notmuch_mailstore_open (mailstore, filename);
if (! mctx->file) {
fprintf (stderr, "Error opening %s: %s\n", filename, strerror (errno));
status = NOTMUCH_STATUS_FILE_ERROR;
diff --git a/notmuch-client.h b/notmuch-client.h
index c1c30a2..405aad7 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -188,6 +188,7 @@ query_string_from_args (void *ctx, int argc, char *argv[]);
notmuch_status_t
show_message_body (notmuch_message_t *message,
+ notmuch_mailstore_t *mailstore,
const notmuch_show_format_t *format,
notmuch_show_params_t *params);
@@ -372,6 +373,7 @@ typedef struct mime_node {
*/
notmuch_status_t
mime_node_open (const void *ctx, notmuch_message_t *message,
+ notmuch_mailstore_t *mailstore,
#ifdef GMIME_ATLEAST_26
GMimeCryptoContext *cryptoctx,
#else
diff --git a/notmuch-reply.c b/notmuch-reply.c
index cb1dd6e..523e2d0 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -587,7 +587,7 @@ notmuch_reply_format_default(void *ctx,
notmuch_message_get_header (mailstore, message, "date"),
notmuch_message_get_header (mailstore, message, "from"));
- show_message_body (message, format, params);
+ show_message_body (message, mailstore, format, params);
notmuch_message_destroy (message);
}
diff --git a/notmuch-show.c b/notmuch-show.c
index 81d4cf0..0d2a246 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -285,7 +285,7 @@ format_message_mbox (const void *ctx,
ssize_t line_len;
filename = notmuch_message_get_filename (message);
- file = fopen (filename, "r");
+ file = notmuch_mailstore_open (mailstore, filename);
if (file == NULL) {
fprintf (stderr, "Failed to open %s: %s\n",
filename, strerror (errno));
@@ -830,7 +830,8 @@ show_message (void *ctx,
void *local = talloc_new (ctx);
mime_node_t *root, *part;
- if (mime_node_open (local, message, params->cryptoctx, params->decrypt,
+ if (mime_node_open (local, message, mailstore,
+ params->cryptoctx, params->decrypt,
&root) == NOTMUCH_STATUS_SUCCESS &&
(part = mime_node_seek_dfs (root, (params->part < 0 ?
0 : params->part))))
@@ -853,7 +854,7 @@ show_message (void *ctx,
}
if (format->part_content)
- show_message_body (message, format, params);
+ show_message_body (message, mailstore, format, params);
if (params->part <= 0) {
fputs (format->body_end, stdout);
@@ -955,7 +956,7 @@ do_show_single (void *ctx,
return 1;
}
- file = fopen (filename, "r");
+ file = notmuch_mailstore_open (mailstore, filename);
if (file == NULL) {
fprintf (stderr, "Error: Cannot open file %s: %s\n", filename, strerror (errno));
return 1;
diff --git a/show-message.c b/show-message.c
index 83ecf81..aed9d3e 100644
--- a/show-message.c
+++ b/show-message.c
@@ -80,6 +80,7 @@ show_message_part (mime_node_t *node,
notmuch_status_t
show_message_body (notmuch_message_t *message,
+ notmuch_mailstore_t *mailstore,
const notmuch_show_format_t *format,
notmuch_show_params_t *params)
{
@@ -87,7 +88,7 @@ show_message_body (notmuch_message_t *message,
show_message_state_t state;
mime_node_t *root, *part;
- ret = mime_node_open (NULL, message, params->cryptoctx, params->decrypt,
+ ret = mime_node_open (NULL, message, mailstore, params->cryptoctx, params->decrypt,
&root);
if (ret)
return ret;
--
1.7.5.4
More information about the notmuch
mailing list