Commit 80ac5faf 80ac5fafd183f5fda1cc62ed8f69db8711840b0c by Sergey Poznyakoff

use util_error() instead of printing diagnostics to ofile.

1 parent b1a90ab4
......@@ -95,7 +95,7 @@ alias_rehash()
if (++hash_num >= max_rehash)
{
fprintf(ofile, "alias hash table full\n");
util_error("alias hash table full");
return 1;
}
......@@ -196,7 +196,7 @@ alias_print(char *name)
if (!alias_lookup(name, &list))
{
fprintf (ofile, "\"%s\": not a group\n", name);
util_error("\"%s\": not a group", name);
return;
}
alias_print_group(name, list);
......
......@@ -60,7 +60,7 @@ mail_copy0 (int argc, char **argv, int mark)
if (mailbox_create_default (&mbx, filename)
|| mailbox_open (mbx, MU_STREAM_WRITE | MU_STREAM_CREAT))
{
fprintf (ofile, "can't create mailbox %s\n", filename);
util_error ("can't create mailbox %s", filename);
free (filename);
free (msglist);
return 1;
......
......@@ -56,13 +56,13 @@ mail_file (int argc, char **argv)
name = NULL; /* our system mailbox */
else
{
fprintf (ofile, "%%user not supported\n");
util_error("%%user not supported");
return 1;
}
break;
case '#':
fprintf (ofile, "# notation not supported\n");
util_error("# notation not supported");
return 1;
case '&':
......@@ -102,7 +102,7 @@ mail_file (int argc, char **argv)
}
else
{
fprintf (ofile, "%s takes only one arg\n", argv[0]);
util_error("%s takes only one arg", argv[0]);
}
return 1;
}
......
......@@ -29,7 +29,7 @@ mail_folders (int argc, char **argv)
if (!env->set)
{
fprintf(ofile, "No value set for \"folder\"\n");
util_error("No value set for \"folder\"");
return 1;
}
......
......@@ -27,16 +27,17 @@ mail_followup (int argc, char **argv)
{
message_t msg;
header_t hdr;
char *to = NULL, *subj = NULL;
char *str;
int i, num, *msglist;
char *savefile = NULL;
struct send_environ env;
int status;
env.to = env.cc = env.bcc = env.subj = NULL;
num = util_expand_msglist (argc, argv, &msglist);
if (mailbox_get_message(mbox, cursor, &msg))
{
fprintf(ofile, "%d: can't get message\n", cursor);
util_error("%d: can't get message", cursor);
free(msglist);
return 1;
}
......@@ -44,22 +45,24 @@ mail_followup (int argc, char **argv)
/* Create subject value */
message_get_header(msg, &hdr);
header_aget_value(hdr, MU_HEADER_SUBJECT, &str);
util_strcat(&subj, "Re: ");
util_strcat(&subj, str);
util_strcat(&env.subj, "Re: ");
util_strcat(&env.subj, str);
free(str);
/* Generate "to" list */
to = util_get_sender(cursor, 0);
env.to = util_get_sender(cursor, 0);
/* Add authors of the subsequent messages to the to list
(or should it be cc?)*/
for (i = 1; i < num; i++)
util_strcat(&to, util_get_sender(msglist[i], 0));
util_strcat(&env.to, util_get_sender(msglist[i], 0));
free(msglist);
fprintf(ofile, "To: %s\n", to);
fprintf(ofile, "Subject: %s\n\n", subj);
fprintf(ofile, "To: %s\n", env.to);
fprintf(ofile, "Subject: %s\n\n", env.subj);
return mail_send0(to, NULL, NULL, subj, isupper(argv[0][0]));
status = mail_send0(&env, isupper(argv[0][0]));
free_env_headers (&env);
return status;
}
......
......@@ -26,36 +26,14 @@ int
mail_help (int argc, char **argv)
{
if (argc < 2)
return util_help (mail_command_table, NULL);
else
{
int i = 0;
FILE *out = ofile;
if ((util_find_env("crt"))->set)
out = popen (getenv("PAGER"), "w");
while (mail_command_table[i].synopsis != 0)
fprintf (out, "%s\n", mail_command_table[i++].synopsis);
int status = 0;
if (out != ofile)
pclose (out);
while (--argc)
status |= util_help (mail_command_table, *++argv);
return 0;
}
else
{
int status = 0, cmd = 0;
while (++cmd < argc)
{
struct mail_command_entry entry = util_find_entry (argv[cmd]);
if (entry.synopsis != NULL)
fprintf (ofile, "%s\n", entry.synopsis);
else
{
status = 1;
fprintf (ofile, "Unknown command: %s\n", argv[cmd]);
}
}
return status;
}
return 1;
......
......@@ -34,7 +34,7 @@ mail_hold (int argc, char **argv)
{
if (mailbox_get_message (mbox, cursor, &msg))
{
fprintf (ofile, "%d: can't get message\n", cursor);
util_error("%d: can't get message", cursor);
return 1;
}
......
......@@ -33,7 +33,7 @@ mail_mbox (int argc, char **argv)
{
if (mailbox_get_message (mbox, cursor, &msg))
{
fprintf (ofile, "%d: can't get message\n", cursor);
util_error("%d: can't get message", cursor);
return 1;
}
/* Mark the message */
......
......@@ -95,3 +95,5 @@ mail_print (int argc, char **argv)
}
return 1;
}
......
......@@ -64,7 +64,7 @@ mail_mbox_commit ()
{
if (mailbox_get_message (mbox, i, &msg))
{
fprintf (ofile, "%d: can't get message\n", i);
util_error("%d: can't get message", i);
return 1;
}
message_get_attribute (msg, &attr);
......@@ -78,7 +78,7 @@ mail_mbox_commit ()
|| mailbox_open (dest_mbox,
MU_STREAM_WRITE | MU_STREAM_CREAT))
{
fprintf (ofile, "can't create mailbox %s\n", name);
util_error("can't create mailbox %s", name);
return 1;
}
}
......
......@@ -33,18 +33,21 @@ mail_reply(int argc, char **argv)
{
message_t msg;
header_t hdr;
char *to = NULL, *cc = NULL, *subj = NULL;
struct send_environ env;
int status;
char *str;
env.to = env.cc = env.bcc = env.subj = NULL;
if (mailbox_get_message(mbox, cursor, &msg))
{
fprintf(ofile, "%d: can't get message\n", cursor);
util_error("%d: can't get message", cursor);
return 1;
}
message_get_header(msg, &hdr);
to = util_get_sender(cursor, 0);
env.to = util_get_sender(cursor, 0);
if (islower(argv[0][0]))
{
/* Add all recepients of the originate letter */
......@@ -63,28 +66,30 @@ mail_reply(int argc, char **argv)
for (i = 1; i <= count; i++)
{
address_get_email(addr, i, buf, sizeof(buf), NULL);
if (!mail_is_alt_name(buf))
if (!mail_is_my_name(buf))
{
util_strcat(&to, " ");
util_strcat(&to, buf);
util_strcat(&env.to, " ");
util_strcat(&env.to, buf);
}
}
/* Finally, add any Ccs */
header_aget_value(hdr, MU_HEADER_CC, &cc);
header_aget_value(hdr, MU_HEADER_CC, &env.cc);
}
header_aget_value(hdr, MU_HEADER_SUBJECT, &str);
util_strcat(&subj, "Re: ");
util_strcat(&subj, str);
util_strcat(&env.subj, "Re: ");
util_strcat(&env.subj, str);
free(str);
fprintf(ofile, "To: %s\n", to);
if (cc)
fprintf(ofile, "Cc: %s\n", cc);
fprintf(ofile, "Subject: %s\n\n", subj);
fprintf(ofile, "To: %s\n", env.to);
if (env.cc)
fprintf(ofile, "Cc: %s\n", env.cc);
fprintf(ofile, "Subject: %s\n\n", env.subj);
return mail_send0(to, cc, NULL, subj, 0);
status = mail_send0(&env, 0);
free_env_headers (&env);
return status;
}
return 1;
}
......
......@@ -32,7 +32,7 @@ mail_size (int argc, char **argv)
message_t msg;
if (mailbox_get_message (mbox, cursor, &msg) != 0)
{
fprintf (stderr, "Could not read message %d\n", cursor);
util_error("Could not read message %d", cursor);
return 1;
}
message_size (msg, &s);
......
......@@ -26,7 +26,7 @@ mail_unalias (int argc, char **argv)
{
if (argc == 1)
{
fprintf (ofile, "unalias requires at least one argument\n");
util_error("unalias requires at least one argument");
return 1;
}
while (--argc)
......
......@@ -32,7 +32,7 @@ mail_undelete (int argc, char **argv)
attribute_t attr;
if (mailbox_get_message (mbox, cursor, &msg) != 0)
{
fprintf (stderr, "Meessage %d does not exist\n", cursor);
util_error("Message %d does not exist", cursor);
return 1;
}
message_get_attribute (msg, &attr);
......
......@@ -37,7 +37,7 @@ mail_write (int argc, char **argv)
int *msglist = NULL;
int num = 0, i = 0;
int sender = 0;
size_t total_size, total_lines, size;
size_t total_size = 0, total_lines = 0, size;
if (isupper (argv[0][0]))
sender = 1;
......@@ -63,7 +63,7 @@ mail_write (int argc, char **argv)
output = fopen (filename, "a");
if (!output)
{
fprintf (ofile, "can't open %s: %s\n", filename, strerror (errno));
util_error("can't open %s: %s", filename, strerror (errno));
free (filename);
fclose (output);
free (msglist);
......
......@@ -60,7 +60,7 @@ z_parse_args(int argc, char **argv, int *return_count, int *return_dir)
dir = D_NONE;
break;
default:
fprintf(ofile, "Bad arguments for the scrolling command\n");
util_error("Bad arguments for the scrolling command");
return 1;
}
......@@ -75,7 +75,7 @@ z_parse_args(int argc, char **argv, int *return_count, int *return_dir)
if (argc > 1)
{
fprintf(ofile, "Too many arguments for the scrolling command\n");
util_error("Too many arguments for the scrolling command");
return 1;
}
......@@ -83,13 +83,13 @@ z_parse_args(int argc, char **argv, int *return_count, int *return_dir)
{
if (dir == D_NONE)
{
fprintf(ofile, "argument no applicable for z.\n");
util_error("argument not applicable for z.");
return 1;
}
if ((mul = atoi(argp)) == 0)
{
fprintf(ofile, "Bad number of pages\n");
util_error("Bad number of pages");
return 1;
}
}
......