#include <limits.h>
#include <sys/wait.h>
#include <sys/stat.h>
-#include <sys/time.h>
+
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+# include <sys/time.h>
+# else
+# include <time.h>
+# endif
+#endif
+
#include <stdarg.h>
#include "citadel.h"
#include "messages.h"
#include "snprintf.h"
#endif
-#define MAXWORDBUF 256
+#define MAXWORDBUF SIZ
#define MAXMSGS 512
struct cittext {
void ka_sigcatch(int signum)
{
- char buf[256];
+ char buf[SIZ];
alarm(S_KEEPALIVE);
signal(SIGALRM, ka_sigcatch);
serv_puts("NOOP");
long num, /* message number */
char pagin) /* 0 = normal read, 1 = read with pagination, 2 = header */
{
- char buf[256];
- char m_subject[256];
- char from[256], node[256], rfca[256];
- char now[256];
+ char buf[SIZ];
+ char m_subject[SIZ];
+ char from[SIZ], node[SIZ], rfca[SIZ];
+ char now[SIZ];
int format_type = 0;
int fr = 0;
int nhdr = 0;
* Function to begin composing a new message
*/
int make_message(char *filename, /* temporary file name */
- char *recipient, /* NULL if it's not mail */
- int anon_type, /* see MES_ types in header file */
- int format_type, int mode)
+ char *recipient, /* NULL if it's not mail */
+ int anon_type, /* see MES_ types in header file */
+ int format_type,
+ int mode)
{
FILE *fp;
int a, b, e_ex_code;
if (room_flags & QR_ANONONLY) {
printf(" ****");
- } else {
+ }
+ else {
printf(" %s from %s", datestr, fullname);
- if (strlen(recipient) > 0)
+ if (strlen(recipient) > 0) {
printf(" to %s", recipient);
+ }
}
printf("\n");
beg = 0L;
- if (mode == 1)
+ if (mode == 1) {
printf("(Press ctrl-d when finished)\n");
+ }
if (mode == 0) {
fp = fopen(filename, "r");
if (fp != NULL) {
fclose(fp);
} else {
fp = fopen(filename, "w");
+ if (fp == NULL) {
+ printf("*** Error opening temp file!\n"
+ " %s: %s\n",
+ filename, strerror(errno));
+ return(1);
+ }
fclose(fp);
}
}
case 0:
fp = fopen(filename, "r+");
+ if (fp == NULL) {
+ printf("*** Error opening temp file!\n"
+ " %s: %s\n",
+ filename, strerror(errno));
+ return(1);
+ }
citedit(fp);
fclose(fp);
goto MECR;
case 1:
fp = fopen(filename, "w");
+ if (fp == NULL) {
+ printf("*** Error opening temp file!\n"
+ " %s: %s\n",
+ filename, strerror(errno));
+ return(1);
+ }
do {
a = inkey();
if (a == 255)
*/
void transmit_message(FILE *fp)
{
- char buf[256];
+ char buf[SIZ];
int ch, a;
long msglen;
time_t lasttick;
int c) /* */
{
char buf[300];
- char cmd[256];
+ char cmd[SIZ];
int a, b;
int need_recp = 0;
int mode;
return (2);
}
- /* ...and transmit it to the server. */
+ /* Reopen the temp file that was created, so we can send it */
+ fp = fopen(temp, "r");
+
+ /* Yes, unlink it now, so it doesn't stick around if we crash */
+ unlink(temp);
+
+ if (fp == NULL) {
+ printf("*** Internal error while trying to save message!\n"
+ " %s: %s\n",
+ temp, strerror(errno));
+ return(errno);
+ }
+
+ /* Transmit message to the server */
sprintf(cmd, "ENT0 1|%s|%d|%d||", buf, b, mode);
serv_puts(cmd);
serv_gets(cmd);
printf("%s\n", &cmd[4]);
return (1);
}
- fp = fopen(temp, "r");
- if (fp != NULL) {
- transmit_message(fp);
- fclose(fp);
- }
+
+ transmit_message(fp);
serv_puts("000");
- unlink(temp);
+
+ fclose(fp);
highmsg = msg_arr[num_msgs - 1];
num_msgs = 0;
/* now see if anyone else has posted in here */
b = (-1);
- for (a = 0; a < num_msgs; ++a)
- if (msg_arr[a] > highmsg)
+ for (a = 0; a < num_msgs; ++a) {
+ if (msg_arr[a] > highmsg) {
++b;
+ }
+ }
- /* in the Mail> room, this algorithm always counts one message
- * higher than in public rooms, so we decrement it by one */
- if (need_recp)
+ /* In the Mail> room, this algorithm always counts one message
+ * higher than in public rooms, so we decrement it by one.
+ */
+ if (need_recp) {
--b;
+ }
if (b == 1) {
printf("*** 1 additional message has been entered "
void list_urls()
{
int i;
- char cmd[256];
+ char cmd[SIZ];
if (num_urls == 0) {
printf("There were no URL's in the previous message.\n\n");
int q /* Number of msgs to read (if c==3) */
) {
int a, b, e, f, g, start;
+ int savedpos;
int hold_sw = 0;
char arcflag = 0;
char quotflag = 0;
int hold_color = 0;
char prtfile[PATH_MAX];
char pagin;
- char cmd[256];
+ char cmd[SIZ];
char targ[ROOMNAMELEN];
- char filename[256];
+ char filename[SIZ];
if (c < 0)
b = (MAXMSGS - 1);
}
}
+ if (num_msgs == 0) {
+ printf("*** There are no ");
+ if (c == 1) printf("new ");
+ if (c == 2) printf("old ");
+ printf("messages in this room.\n");
+ return;
+ }
+
lines_printed = 0;
/* this loop cycles through each message... */
return;
}
- RAGAIN:pagin = ((arcflag == 0)
+RAGAIN: pagin = ((arcflag == 0)
&& (quotflag == 0)
&& (userflags & US_PAGINATOR)) ? 1 : 0;
read_message(msg_arr[a], READ_HEADER);
goto RMSGREAD;
case 'r':
+ savedpos = num_msgs;
entmsg(1, (DEFAULT_ENTRY == 46 ? 2 : 0));
+ num_msgs = savedpos;
goto RMSGREAD;
case 'u':
list_urls();
*/
void check_message_base(void)
{
- char buf[256];
+ char buf[SIZ];
printf
("Please read the documentation before running this command.\n"