* Began working on address book view
authorArt Cancro <ajc@citadel.org>
Thu, 9 May 2002 03:53:56 +0000 (03:53 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 9 May 2002 03:53:56 +0000 (03:53 +0000)
webcit/ChangeLog
webcit/context_loop.c
webcit/messages.c
webcit/vcard_edit.c
webcit/webcit.c

index c41e280c2a4a49a2eb47ef45509d335cde7859a2..66b3eb100c2e54ae6be1e34bb01fe2511d0622d8 100644 (file)
@@ -1,4 +1,7 @@
 $Log$
+Revision 323.31  2002/05/09 03:53:56  ajc
+* Began working on address book view
+
 Revision 323.30  2002/05/08 03:38:58  ajc
 * Preferences framework
 
@@ -806,4 +809,3 @@ Sun Dec  6 19:50:55 EST 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
 
 1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
        * webserver.c: warning fix
-
index 30a41e41b250652b83461b2c2b5d5401ae116cb0..e979beeb8b17a9fe911df0f8b86b4183c19a06c9 100644 (file)
@@ -286,7 +286,6 @@ void context_loop(int sock)
        }
 
 
-
        /*
         * See if there's an existing session open with the desired ID
         */
index e949d12a5ea1a0e540e9ad83361dd97896a500ee..bf44814d938bf7d22a96c3506da347cefed2ebd8 100644 (file)
@@ -82,19 +82,13 @@ char buf[];
 }
 
 
-
-
-/*
- * Experimental output type of thing
+/* display_vcard() calls this after parsing the textual vCard into
+ * our 'struct vCard' data object.
  */
-void display_vcard(char *vcard_source) {
+void display_parsed_vcard(struct vCard *v) {
        int i, j;
-       struct vCard *v;
        char buf[SIZ];
 
-       v = vcard_load(vcard_source);
-       if (v == NULL) return;
-
        wprintf("<TABLE bgcolor=#888888>");
        if (v->numprops) for (i=0; i<(v->numprops); ++i) {
                if (!strcasecmp(v->prop[i].name, "n")) {
@@ -144,8 +138,36 @@ void display_vcard(char *vcard_source) {
                        wprintf("</TD></TR>\n");
                }
        }
-
        wprintf("</TABLE>\n");
+}
+
+
+
+/*
+ * Experimental output type of thing
+ */
+void display_vcard(char *vcard_source, char alpha) {
+       struct vCard *v;
+       char *name;
+       char buf[SIZ];
+       char this_alpha = 0;
+
+       v = vcard_load(vcard_source);
+       if (v == NULL) return;
+
+       name = vcard_get_prop(v, "n", 1, 0, 0);
+       if (name != NULL) {
+               strcpy(buf, name);
+               this_alpha = buf[0];
+       }
+
+       if ( (alpha == 0)
+          || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
+          || ((!isalpha(alpha)) && (!isalpha(this_alpha))) ) {
+
+               display_parsed_vcard(v);
+
+       }
 
        vcard_free(v);
 }
@@ -399,7 +421,7 @@ void read_message(long msgnum) {
                        }
 
                        /* In all cases, display it */
-                       display_vcard(vcard_source);
+                       display_vcard(vcard_source, 0);
                        free(vcard_source);
                }
        }
@@ -476,6 +498,70 @@ void summarize_message(long msgnum) {
 
 
 
+void display_addressbook(long msgnum, char alpha) {
+       char buf[SIZ];
+       char mime_partnum[SIZ];
+       char mime_filename[SIZ];
+       char mime_content_type[SIZ];
+       char mime_disposition[SIZ];
+       int mime_length;
+       char vcard_partnum[SIZ];
+       char *vcard_source = NULL;
+
+       struct {
+               char date[SIZ];
+               char from[SIZ];
+               char to[SIZ];
+               char subj[SIZ];
+               int hasattachments;
+       } summ;
+
+       memset(&summ, 0, sizeof(summ));
+       strcpy(summ.subj, "(no subject)");
+
+       sprintf(buf, "MSG0 %ld|1", msgnum);     /* ask for headers only */
+       serv_puts(buf);
+       serv_gets(buf);
+       if (buf[0] != '1') return;
+
+       while (serv_gets(buf), strcmp(buf, "000")) {
+               if (!strncasecmp(buf, "part=", 5)) {
+                       extract(mime_filename, &buf[5], 1);
+                       extract(mime_partnum, &buf[5], 2);
+                       extract(mime_disposition, &buf[5], 3);
+                       extract(mime_content_type, &buf[5], 4);
+                       mime_length = extract_int(&buf[5], 5);
+
+                       if (!strcasecmp(mime_content_type, "text/x-vcard")) {
+                               strcpy(vcard_partnum, mime_partnum);
+                       }
+
+               }
+       }
+
+       if (strlen(vcard_partnum) > 0) {
+               vcard_source = load_mimepart(msgnum, vcard_partnum);
+               if (vcard_source != NULL) {
+
+                       /* If it's my vCard I can edit it */
+                       if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
+                          || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))) {
+                               wprintf("<A HREF=\"/edit_vcard?"
+                                       "msgnum=%ld&partnum=%s\">",
+                                       msgnum, vcard_partnum);
+                               wprintf("(edit)</A>");
+                       }
+
+                       /* In all cases, display it */
+                       display_vcard(vcard_source, alpha);
+                       free(vcard_source);
+               }
+       }
+
+}
+
+
+
 /* 
  * load message pointers from the server
  */
@@ -506,12 +592,14 @@ char *servcmd;
 void readloop(char *oper)
 {
        char cmd[SIZ];
-       int a, b;
+       char buf[SIZ];
+       int a, b, i;
        int nummsgs;
        long startmsg;
        int maxmsgs;
        int num_displayed = 0;
        int is_summary = 0;
+       int is_addressbook = 0;
        int remaining_messages;
        int lo, hi;
        int lowest_displayed = (-1);
@@ -520,6 +608,7 @@ void readloop(char *oper)
        long pn_current = 0L;
        long pn_next = 0L;
        int bg = 0;
+       char alpha = 0;
 
        startmsg = atol(bstr("startmsg"));
        maxmsgs = atoi(bstr("maxmsgs"));
@@ -540,6 +629,31 @@ void readloop(char *oper)
        if ((WC->wc_view == 1) && (maxmsgs > 1)) {
                is_summary = 1;
                strcpy(cmd, "MSGS ALL");
+               maxmsgs = 32767;
+       }
+       if ((WC->wc_view == 2) && (maxmsgs > 1)) {
+               is_addressbook = 1;
+               strcpy(cmd, "MSGS ALL");
+               maxmsgs = 32767;
+               if (bstr("alpha") == NULL) {
+                       alpha = 'A';
+               }
+               else {
+                       strcpy(buf, bstr("alpha"));
+                       alpha = buf[0];
+               }
+
+               for (i='A'; i<='Z'; ++i) {
+                       if (i == alpha) wprintf("<FONT SIZE=+2>"
+                                               "%c</FONT>\n", i);
+                       else {
+                               wprintf("<A HREF=\"/readfwd?alpha=%c\">"
+                                       "%c</A>\n", i, i);
+                       }
+                       wprintf("&nbsp;");
+               }
+               wprintf("<A HREF=\"/readfwd?alpha=1\">(other)</A>\n");
+               wprintf("<HR width=100%%>\n");
        }
 
        nummsgs = load_msg_ptrs(cmd);
@@ -593,6 +707,9 @@ void readloop(char *oper)
                                summarize_message(WC->msgarr[a]);
                                wprintf("</TR>\n");
                        }
+                       else if (is_addressbook) {
+                               display_addressbook(WC->msgarr[a], alpha);
+                       }
                        else {
                                read_message(WC->msgarr[a]);
                        }
index af5df8bad6c2326d75b2d9258727e86c3dc2c47d..f497730b913a34c58f18e199bb5fd5d3b9692810 100644 (file)
@@ -280,10 +280,8 @@ void submit_vcard(void) {
        }
 
        sprintf(buf, "ENT0 1|||4||");
-       fprintf(stderr, "%s\n", buf);
        serv_puts(buf);
        serv_gets(buf);
-       fprintf(stderr, "%s\n", buf);
        if (buf[0] != '4') {
                edit_vcard();
                return;
index b93114efa15f158bae90d23a6619afc0cc4ac477..97dec65b0e112911829d39a246bae7c8324b0409 100644 (file)
@@ -29,6 +29,7 @@
 #include <pthread.h>
 #include <signal.h>
 #include "webcit.h"
+#include "webserver.h"
 #include "mime_parser.h"
 
 /*
@@ -435,7 +436,7 @@ void output_static(char *what)
 
                fstat(fileno(fp), &statbuf);
                bytes = statbuf.st_size;
-               fprintf(stderr, "Static: %s, %ld bytes\n", what, bytes);
+               lprintf(3, "Static: %s, %ld bytes\n", what, bytes);
                wprintf("Content-length: %ld\n", (long) bytes);
                wprintf("\n");
                bigbuffer = malloc(bytes);
@@ -462,7 +463,7 @@ void output_image()
        off_t thisblock;
        off_t accomplished = 0L;
 
-
+       lprintf(5, "output_image() called\n");
        serv_printf("OIMG %s|%s", bstr("name"), bstr("parm"));
        serv_gets(buf);
        if (buf[0] == '2') {
@@ -682,12 +683,12 @@ void upload_handler(char *name, char *filename, char *partnum, char *disp,
                        char *encoding, void *userdata)
 {
 
-       fprintf(stderr, "UPLOAD HANDLER CALLED\n");
-       fprintf(stderr, "    name = %s\n", name);
-       fprintf(stderr, "filename = %s\n", filename);
-       fprintf(stderr, "encoding = %s\n", encoding);
-       fprintf(stderr, "    type = %s\n", cbtype);
-       fprintf(stderr, "  length = %ld\n", (long)length);
+       lprintf(5, "UPLOAD HANDLER CALLED\n");
+       lprintf(5, "    name = %s\n", name);
+       lprintf(5, "filename = %s\n", filename);
+       lprintf(5, "encoding = %s\n", encoding);
+       lprintf(5, "    type = %s\n", cbtype);
+       lprintf(5, "  length = %ld\n", (long)length);
 
        if (length > 0) {
                WC->upload = malloc(length);
@@ -696,7 +697,7 @@ void upload_handler(char *name, char *filename, char *partnum, char *disp,
                        memcpy(WC->upload, content, length);
                }
                else {
-                       fprintf(stderr, "malloc() failed: %s\n",
+                       lprintf(9, "malloc() failed: %s\n",
                                strerror(errno));
                }
        }
@@ -768,7 +769,7 @@ void session_loop(struct httprequest *req)
        }
 
        if (ContentLength > 0) {
-               fprintf(stderr, "Content length: %d\n", ContentLength);
+               lprintf(5, "Content length: %d\n", ContentLength);
                content = malloc(ContentLength + 1);
                memset(content, 0, ContentLength+1);
                BytesRead = 0;