User Biography display: remove call, do through templates directly.
[citadel.git] / citadel / textclient / messages.c
index 14c4fd9d7fe85df388ea022215e72d4e3d233ef5..6cc8f6a6f09017a81c321a9bbce98601d599afc8 100644 (file)
@@ -48,6 +48,7 @@
 #include "citadel_decls.h"
 #include "messages.h"
 #include "commands.h"
+#include "tuiconfig.h"
 #include "rooms.h"
 #ifndef HAVE_SNPRINTF
 #include "snprintf.h"
@@ -69,14 +70,12 @@ struct cittext {
 
 void stty_ctdl(int cmd);
 int haschar(const char *st, int ch);
-void ctdl_getline(char *string, int lim);
 int file_checksum(char *filename);
 void progress(CtdlIPC* ipc, unsigned long curr, unsigned long cmax);
 
 unsigned long *msg_arr = NULL;
 int msg_arr_size = 0;
 int num_msgs;
-char rc_alt_semantics;
 extern char room_name[];
 extern char tempdir[];
 extern unsigned room_flags;
@@ -387,6 +386,50 @@ void free_parts(struct parts *p)
 }
 
 
+/*
+ * This is a mini RFC2047 decoder.
+ * It only handles strings encoded from UTF-8 as Quoted-printable.
+ */
+void mini_2047_decode(char *s) {
+       if (!s) return;
+
+       char *qstart = strstr(s, "=?UTF-8?Q?");
+       if (!qstart) return;
+
+       char *qend = strstr(s, "?=");
+       if (!qend) return;
+
+       if (qend <= qstart) return;
+
+       strcpy(qstart, &qstart[10]);
+       qend -= 10;
+
+       char *p = qstart;
+       while (p < qend) {
+
+               if (p[0] == '=') {
+
+                       char ch[3];
+                       ch[0] = p[1];
+                       ch[1] = p[2];
+                       ch[2] = p[3];
+                       int c;
+                       sscanf(ch, "%02x", &c);
+                       p[0] = c;
+                       strcpy(&p[1], &p[3]);
+                       qend -= 2;
+               }
+
+               if (p[0] == '_') {
+                       p[0] = ' ';
+               }
+               
+               ++p;
+       }
+
+       strcpy(qend, &qend[2]);
+}
+
 /*
  * Read a message from the server
  */
@@ -468,7 +511,8 @@ int read_message(CtdlIPC *ipc,
                                scr_printf("part=%s|%s|%s|%s|%s|%ld\n",
                                        ptr->name, ptr->filename, ptr->number,
                                        ptr->disposition, ptr->mimetype,
-                                       ptr->length);
+                                       ptr->length
+                               );
                        }
                }
                scr_printf("\n");
@@ -607,12 +651,12 @@ int read_message(CtdlIPC *ipc,
                safestrncpy(reply_subject, message->subject, sizeof reply_subject);
                if (!IsEmptyStr(message->subject)) {
                        if (dest) {
-                               fprintf(dest, "Subject: %s\n",
-                                                       message->subject);
+                               fprintf(dest, "Subject: %s\n", message->subject);
                        } else {
                                color(DIM_WHITE);
                                scr_printf("Subject: ");
                                color(BRIGHT_CYAN);
+                               mini_2047_decode(message->subject);
                                scr_printf("%s\n", message->subject);
                        }
                }
@@ -766,14 +810,12 @@ void replace_string(char *filename, long int startpos)
        long msglen = 0L;
        int rv;
 
-       scr_printf("Enter text to be replaced:\n: ");
-       ctdl_getline(srch_str, (sizeof(srch_str)-1) );
+       newprompt("Enter test to be replaced: ", srch_str, (sizeof(srch_str)-1) );
        if (IsEmptyStr(srch_str)) {
                return;
        }
 
-       scr_printf("Enter text to replace it with:\n: ");
-       ctdl_getline(rplc_str, (sizeof(rplc_str)-1) );
+       newprompt("Enter text to replace it with: ", rplc_str, (sizeof(rplc_str)-1) );
 
        fp = fopen(filename, "r+");
        if (fp == NULL) {
@@ -834,21 +876,11 @@ int client_make_message(CtdlIPC *ipc,
        long beg;
        char datestr[SIZ];
        char header[SIZ];
-       char *editor_path = NULL;
        int cksum = 0;
 
-       if (mode >= 2)
-       {
-               if ((mode-2) < MAX_EDITORS && !IsEmptyStr(editor_paths[mode-2]))
-               {
-                       editor_path = editor_paths[mode-2];
-               } else if (!IsEmptyStr(editor_paths[0]))
-               {
-                       editor_path = editor_paths[0];
-               } else {
-                       scr_printf("*** No editor available; using built-in editor.\n");
-                       mode = 0;
-               }
+       if ( (mode == 2) && (IsEmptyStr(editor_path)) ) {
+               scr_printf("*** No editor available; using built-in editor.\n");
+               mode = 0;
        }
 
        fmt_date(datestr, sizeof datestr, time(NULL), 0);
@@ -1002,7 +1034,6 @@ MECR:     if (mode >= 2) {
                fp = fopen(filename, "r");
                if (fp != NULL) {
                        fmout(screenwidth, fp, NULL, NULL, 0);
-                       /* TODO: why ftell if we ignore the result? */
                        beg = ftell(fp);
                        if (beg < 0)
                                scr_printf("failed to get stream position %s\n", 
@@ -1181,10 +1212,10 @@ int entmsg(CtdlIPC *ipc,
                        if (is_reply) {
                                strcpy(buf, reply_to);
                        } else {
-                               scr_printf("Enter recipient: ");
-                               ctdl_getline(buf, (SIZ-100) );
-                               if (IsEmptyStr(buf))
+                               newprompt("Enter recipient: ", buf, SIZ-100);
+                               if (IsEmptyStr(buf)) {
                                        return (1);
+                               }
                        }
                } else
                        strcpy(buf, "sysop");
@@ -1321,12 +1352,10 @@ void process_quote(void)
        while (fgets(buf, 128, qfile) != NULL) {
                scr_printf("%3d %s", ++line, buf);
        }
-       scr_printf("Begin quoting at [1] : ");
-       ctdl_getline(buf, 4);
-       qstart = (buf[0] == 0) ? (1) : atoi(buf);
-       scr_printf("  End quoting at [%d] : ", line);
-       ctdl_getline(buf, 4);
-       qend = (buf[0] == 0) ? (line) : atoi(buf);
+
+       qstart = intprompt("Begin quoting at", 1, 1, line);
+       qend = intprompt("  End quoting at", line, qstart, line);
+
        rewind(qfile);
        line = 0;
        if (fgets(buf, 128, qfile) == NULL) {
@@ -1615,11 +1644,6 @@ RMSGREAD:
                                } while ((g != f) && (g >= 0));
                        scr_printf("Message printed.\n");
                }
-               if (rc_alt_semantics && c == 1) {
-                       char buf[SIZ];
-
-                       r = CtdlIPCSetMessageSeen(ipc, msg_arr[a], 1, buf);
-               }
                if (e == SIGQUIT)
                        return;
                if (((userflags & US_NOPROMPT) || (e == SIGINT))
@@ -1919,37 +1943,6 @@ void edit_system_message(CtdlIPC *ipc, char *which_message)
 
 
 
-/*
- * Verify the message base
- */
-void check_message_base(CtdlIPC *ipc)
-{
-       char buf[SIZ];
-       char *transcript = NULL;
-       int r;          /* IPC response code */
-
-       scr_printf
-           ("Please read the documentation before running this command.\n"
-           "Having done so, do you still want to check the message base? ");
-       if (yesno() == 0)
-               return;
-
-       r = CtdlIPCMessageBaseCheck(ipc, &transcript, buf);
-       if (r / 100 != 1) {
-               scr_printf("%s\n", buf);
-               return;
-       }
-
-       while (transcript && !IsEmptyStr(transcript)) {
-               extract_token(buf, transcript, 0, '\n', sizeof buf);
-               remove_token(transcript, 0, '\n');
-               scr_printf("%s\n", buf);
-       }
-       if (transcript) free(transcript);
-       return;
-}
-
-
 /*
  * Loads the contents of a file into memory.  Caller must free the allocated
  * memory.