In the text client - fixed the logic for determining whether to display the email...
[citadel.git] / textclient / messages.c
index a6d5201728b674ba694828eb0c2d3ce5dfc19718..7fd9502df3831326b3c2afff2563fada38dc121b 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Text client functions for reading and writing of messages
  *
- * Copyright (c) 1987-2018 by the citadel.org team
+ * Copyright (c) 1987-2020 by the citadel.org team
  *
  * This program is open source software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 3.
@@ -66,7 +66,6 @@ int has_images = 0;           /* Current msg has images */
 struct parts *last_message_parts = NULL;       /* Parts from last msg */
 
 
-
 void ka_sigcatch(int signum)
 {
        alarm(S_KEEPALIVE);
@@ -127,7 +126,6 @@ int ka_system(char *shc)
 }
 
 
-
 /*
  * add a newline to the buffer...
  */
@@ -388,13 +386,15 @@ void mini_2047_decode(char *s)
        strcpy(qend, &qend[2]);
 }
 
+
 /*
  * Read a message from the server
  */
-int read_message(CtdlIPC * ipc, long num,      /* message number */
-                int pagin,     /* 0 = normal read, 1 = read with pagination, 2 = header */
-                FILE * dest)
-{                              /* Destination file, NULL for screen */
+int read_message(CtdlIPC *ipc,
+               long num,       /* message number */
+               int pagin,      /* 0 = normal read, 1 = read with pagination, 2 = header */
+               FILE *dest      /* Destination file, NULL for screen */
+) {
        char buf[SIZ];
        char now[256];
        int format_type = 0;
@@ -410,6 +410,7 @@ int read_message(CtdlIPC * ipc, long num,   /* message number */
        char ch;
        int linelen;
        int final_line_is_blank = 0;
+       int is_local = 0;
 
        has_images = 0;
 
@@ -433,7 +434,8 @@ int read_message(CtdlIPC * ipc, long num,   /* message number */
 
        if (dest) {
                fprintf(dest, "\n ");
-       } else {
+       }
+       else {
                scr_printf("\n");
                if (pagin != 2) {
                        scr_printf(" ");
@@ -443,6 +445,18 @@ int read_message(CtdlIPC * ipc, long num,  /* message number */
                color(BRIGHT_CYAN);
        }
 
+       /* Determine if the message originated here on the local system.  If it did we will suppress printing of email addresses */
+       is_local = 0;
+       char *at = !IsEmptyStr(message->email) ? strchr(message->email,'@') : NULL;
+       if (at) {
+               if (!strcasecmp(++at, ipc->ServInfo.fqdn)) {
+                       is_local = 1;
+               }
+       }
+       else {
+               is_local = 1;           // no address means it couldn't have originated anywhere else
+       }
+
        /* View headers only */
        if (pagin == 2) {
                scr_printf("nhdr=%s\nfrom=%s\ntype=%d\nmsgn=%s\n",
@@ -453,8 +467,7 @@ int read_message(CtdlIPC * ipc, long num,   /* message number */
                if (!IsEmptyStr(message->email)) {
                        scr_printf("rfca=%s\n", message->email);
                }
-               scr_printf("room=%s\ntime=%s", message->room, asctime(localtime(&message->time))
-                   );
+               scr_printf("room=%s\ntime=%s", message->room, asctime(localtime(&message->time)));
                if (!IsEmptyStr(message->recipient)) {
                        scr_printf("rcpt=%s\n", message->recipient);
                }
@@ -489,26 +502,29 @@ int read_message(CtdlIPC * ipc, long num, /* message number */
        if (nhdr == 1 && !is_room_aide) {
                if (dest) {
                        fprintf(dest, " ****");
-               } else {
+               }
+               else {
                        scr_printf(" ****");
                }
-       } else {
+       }
+       else {
                struct tm thetime;
                localtime_r(&message->time, &thetime);
                strftime(now, sizeof now, "%F %R", &thetime);
                if (dest) {
                        fprintf(dest, "%s from %s ", now, message->author);
-                       if (!IsEmptyStr(message->email)) {
+                       if (!is_local) {
                                fprintf(dest, "<%s> ", message->email);
                        }
-               } else {
+               }
+               else {
                        color(BRIGHT_CYAN);
                        scr_printf("%s ", now);
                        color(DIM_WHITE);
                        scr_printf("from ");
                        color(BRIGHT_CYAN);
                        scr_printf("%s ", message->author);
-                       if (!IsEmptyStr(message->email)) {
+                       if (!is_local) {
                                color(DIM_WHITE);
                                scr_printf("<");
                                color(BRIGHT_BLUE);
@@ -596,7 +612,7 @@ int read_message(CtdlIPC * ipc, long num,   /* message number */
         * of the client screen.
         */
        if (!strcasecmp(message->content_type, "text/html")) {
-               converted_text = html_to_ascii(message->text, 0, screenwidth, 0);
+               converted_text = html_to_ascii(message->text, 0, screenwidth);
                if (converted_text != NULL) {
                        free(message->text);
                        message->text = converted_text;
@@ -731,6 +747,7 @@ int read_message(CtdlIPC * ipc, long num,   /* message number */
        return (fr);
 }
 
+
 /*
  * replace string function for the built-in editor
  */
@@ -796,6 +813,7 @@ void replace_string(char *filename, long int startpos)
        scr_printf("<R>eplace made %d substitution(s).\n\n", substitutions);
 }
 
+
 /*
  * Function to begin composing a new message
  */
@@ -1049,7 +1067,21 @@ int entmsg(CtdlIPC * ipc, int is_reply,  /* nonzero if this was a <R>eply command
        int r;                  /* IPC response code */
        int subject_required = 0;
 
-       if (!entmsg_ok) {
+       if (entmsg_ok == ENTMSG_OK_YES) {
+               /* no problem, go right ahead */
+       }
+       else if (entmsg_ok == ENTMSG_OK_BLOG) {
+               if (!is_reply) {
+                       scr_printf("WARNING: this is a BLOG room.\n");
+                       scr_printf("The '<E>nter Message' command will create a BLOG POST.\n");
+                       scr_printf("If you want to leave a comment or reply to a comment, use the '<R>eply' command.\n");
+                       scr_printf("Do you really want to create a new blog post? ");
+                       if (!yesno()) {
+                               return(1);
+                       }
+               }
+       }
+       else {
                scr_printf("You may not enter messages in this type of room.\n");
                return (1);
        }
@@ -1244,6 +1276,7 @@ int entmsg(CtdlIPC * ipc, int is_reply,   /* nonzero if this was a <R>eply command
        return (0);
 }
 
+
 /*
  * Do editing on a quoted file
  */
@@ -1278,8 +1311,9 @@ void process_quote(void)
        }
        tfile = fopen(temp, "w");
        while (fgets(buf, 128, qfile) != NULL) {
-               if ((++line >= qstart) && (line <= qend))
+               if ((++line >= qstart) && (line <= qend)) {
                        fprintf(tfile, " >%s", buf);
+               }
        }
        fprintf(tfile, " \n");
        fclose(qfile);
@@ -1288,9 +1322,8 @@ void process_quote(void)
 }
 
 
-
 /*
- * List the URL's which were embedded in the previous message
+ * List the URLs which were embedded in the previous message
  */
 void list_urls(CtdlIPC * ipc)
 {
@@ -1299,7 +1332,7 @@ void list_urls(CtdlIPC * ipc)
        int rv;
 
        if (num_urls == 0) {
-               scr_printf("There were no URL's in the previous message.\n\n");
+               scr_printf("There were no URLs in the previous message.\n\n");
                return;
        }
 
@@ -1312,8 +1345,6 @@ void list_urls(CtdlIPC * ipc)
 
        snprintf(cmd, sizeof cmd, rc_url_cmd, urls[i - 1]);
        rv = system(cmd);
-       if (rv != 0)
-               scr_printf("failed to '%s' by %d\n", cmd, rv);
        scr_printf("\n");
 }
 
@@ -1480,9 +1511,10 @@ void readmsgs(CtdlIPC * ipc, enum MessageList c, /* see listing in citadel_ipc.h
                for (num_msgs = 0; msg_arr[num_msgs]; num_msgs++);
        }
 
-       if (num_msgs == 0) {    /* TODO look at this later */
-               if (c == LastMessages)
+       if (num_msgs == 0) {
+               if (c == LastMessages) {
                        return;
+               }
                scr_printf("*** There are no ");
                if (c == NewMessages)
                        scr_printf("new ");
@@ -1830,8 +1862,6 @@ void readmsgs(CtdlIPC * ipc, enum MessageList c,  /* see listing in citadel_ipc.h
 }                              /* end read routine */
 
 
-
-
 /*
  * View and edit a system message
  */
@@ -1848,11 +1878,8 @@ void edit_system_message(CtdlIPC * ipc, char *which_message)
 }
 
 
-
-
 /*
- * Loads the contents of a file into memory.  Caller must free the allocated
- * memory.
+ * Loads the contents of a file into memory.  Caller must free the allocated memory.
  */
 char *load_message_from_file(FILE * src)
 {