Commit 80a47134 80a471346f08c48d6e51907906296ecb390bdf5b by Sergey Poznyakoff

(util_error_range): New function. Outputs "message

out of range" diagnostics.
(util_get_message): New function. A wrapper around
mailbox_get_message with the proper diagnostics.
1 parent 61594c3a
......@@ -274,7 +274,7 @@ extern int util_getenv __P ((void *ptr, const char *variable,
extern int util_printenv __P ((int set));
extern int util_setenv __P ((const char *name, void *value,
mail_env_data_t type, int overwrite));
extern int util_isdeleted __P ((int message));
extern int util_isdeleted __P ((message_t msg));
extern char *util_get_homedir __P ((void));
extern char *util_fullpath __P ((const char *inpath));
extern char *util_folder_path __P((const char *name));
......@@ -291,6 +291,7 @@ extern void util_escape_percent __P ((char **str));
extern char *util_outfolder_name __P ((char *str));
extern void util_save_outgoing __P ((message_t msg, char *savefile));
extern void util_error __P ((const char *format, ...));
extern int util_error_range __P ((size_t msgno));
extern int util_help __P ((const struct mail_command_entry *table, char *word));
extern int util_tempfile __P ((char **namep));
extern void util_msgset_iterate __P ((msgset_t *msgset, int (*fun) __P ((message_t, msgset_t *, void *)), void *closure));
......@@ -298,6 +299,8 @@ extern int util_get_content_type __P ((header_t hdr, char **value));
extern int util_get_hdr_value __P ((header_t hdr, const char *name, char **value));
extern int util_merge_addresses __P((char **addr_str, const char *value));
extern int util_header_expand __P((header_t *hdr));
extern int util_get_message __P((mailbox_t mbox, size_t msgno,
message_t *msg, int delflag));
extern int ml_got_interrupt __P ((void));
extern void ml_clear_interrupt __P ((void));
......
......@@ -563,16 +563,12 @@ util_setenv (const char *variable, void *value, mail_env_data_t type,
* return 1 if a message is deleted
*/
int
util_isdeleted (int n)
util_isdeleted (message_t msg)
{
message_t msg;
attribute_t attr;
if (mailbox_get_message (mbox, n, &msg) != 0)
return 0;
message_get_attribute (msg, &attr);
if (attribute_is_deleted (attr))
return 1;
return 0;
return attribute_is_deleted (attr);
}
char *
......@@ -918,6 +914,7 @@ util_save_outgoing (message_t msg, char *savefile)
off += n;
}
free (buf);
fprintf (outfile, "\n");
}
fclose (outfile);
}
......@@ -1226,3 +1223,37 @@ util_header_expand (header_t *phdr)
return errcnt;
}
int
util_get_message (mailbox_t mbox, size_t msgno, message_t *msg, int delflag)
{
int status;
if (msgno > total)
{
util_error_range (msgno);
return ENOENT;
}
status = mailbox_get_message (mbox, msgno, msg);
if (status)
{
util_error ("can't get message %lu: %s",
(unsigned long) msgno, mu_errstring (status));
return status;
}
if (delflag && util_isdeleted (*msg))
{
util_error ("%d: Inappropriate message (has been deleted)");
return ENOENT;
}
return 0;
}
int
util_error_range (size_t msgno)
{
util_error ("%d: invalid message number", msgno);
return 1;
}
......