X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fvcard_edit.c;h=6b8e9c8789ba09824c44e2a6860b112a310a9a0f;hb=6c114e1487e4b4032be88563f0f5b76922edd601;hp=ccdaba684e5bf53178b4e0dc723a941971b3f752;hpb=fe6de48992523706b2bfe7e09d5389777970d728;p=citadel.git diff --git a/webcit/vcard_edit.c b/webcit/vcard_edit.c index ccdaba684..6b8e9c878 100644 --- a/webcit/vcard_edit.c +++ b/webcit/vcard_edit.c @@ -100,58 +100,68 @@ void lastfirst_firstlast(char *namebuf) { sprintf(namebuf, "%s; %s", lastname, firstname); } + + +wc_mime_attachment *load_vcard(message_summary *Msg) +{ + HashPos *it; + StrBuf *FoundCharset = NewStrBuf(); + StrBuf *Error; + void *vMime; + const char *Key; + long len; + wc_mime_attachment *Mime; + wc_mime_attachment *VCMime = NULL; + + Msg->MsgBody = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment)); + memset(Msg->MsgBody, 0, sizeof(wc_mime_attachment)); + Msg->MsgBody->msgnum = Msg->msgnum; + + load_message(Msg, FoundCharset, &Error); + + FreeStrBuf(&FoundCharset); + /* look up the vcard... */ + it = GetNewHashPos(Msg->AllAttach, 0); + while (GetNextHashPos(Msg->AllAttach, it, &len, &Key, &vMime) && + (vMime != NULL)) + { + Mime = (wc_mime_attachment*) vMime; + if ((strcmp(ChrPtr(Mime->ContentType), + "text/x-vcard") == 0) || + (strcmp(ChrPtr(Mime->ContentType), + "text/vcard") == 0)) + { + VCMime = Mime; + break; + } + } + DeleteHashPos(&it); + if (VCMime == NULL) + return NULL; + + MimeLoadData(VCMime); + return VCMime; +} + /** * \brief fetch what??? name * \param msgnum the citadel message number * \param namebuf where to put the name in??? */ void fetch_ab_name(message_summary *Msg, char **namebuf) { - 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]; - StrBuf *vcard_source = NULL; - int i, len; - message_summary summ;/// TODO this will lak + long len; + int i; + wc_mime_attachment *VCMime = NULL; if (namebuf == NULL) return; - memset(&summ, 0, sizeof(summ)); - //////safestrncpy(summ.subj, "(no subject)", sizeof summ.subj); - - serv_printf("MSG0 %ld|0", Msg->msgnum); /** unfortunately we need the mime info now */ - serv_getln(buf, sizeof buf); - if (buf[0] != '1') return; - - while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { - if (!strncasecmp(buf, "part=", 5)) { - extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename); - extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum); - extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition); - extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type); - mime_length = extract_int(&buf[5], 5); - - if ( (!strcasecmp(mime_content_type, "text/x-vcard")) - || (!strcasecmp(mime_content_type, "text/vcard")) ) { - strcpy(vcard_partnum, mime_partnum); - } - - } - } - - if (!IsEmptyStr(vcard_partnum)) { - vcard_source = load_mimepart(Msg->msgnum, vcard_partnum); - if (vcard_source != NULL) { + VCMime = load_vcard(Msg); + if (VCMime == NULL) + return; - /* Grab the name off the card */ - display_vcard(WC->WBuf, vcard_source, 0, 0, namebuf, Msg->msgnum); + /* Grab the name off the card */ + display_vcard(WC->WBuf, VCMime->Data, 0, 0, namebuf, Msg->msgnum); - FreeStrBuf(&vcard_source); - } - } if (*namebuf != NULL) { lastfirst_firstlast(*namebuf); striplt(*namebuf); @@ -700,9 +710,9 @@ void do_edit_vcard(long msgnum, char *partnum, wc_mime_attachment *VCAtt, char *return_to, const char *force_room) { + message_summary *Msg = NULL; + wc_mime_attachment *VCMime = NULL; StrBuf *Buf; - char buf[SIZ]; - size_t total_len = 0; struct vCard *v; int i; char *key, *value; @@ -760,36 +770,18 @@ void do_edit_vcard(long msgnum, char *partnum, ((VCMsg != NULL) && (VCAtt != NULL))) { if ((VCMsg == NULL) && (VCAtt == NULL)) { - sprintf(buf, "MSG0 %ld|1", msgnum); - serv_puts(buf); - serv_getln(buf, sizeof buf); - if (buf[0] != '1') { - convenience_page("770000", _("Error"), &buf[4]); - return; - } - while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { - if (!strncasecmp(buf, "from=", 5)) { - safestrncpy(whatuser, &buf[5], sizeof whatuser); - } - else if (!strncasecmp(buf, "node=", 5)) { - strcat(whatuser, " @ "); - strcat(whatuser, &buf[5]); - } - } - Buf = NewStrBuf(); - serv_printf(buf, "DLAT %ld|%s", msgnum, partnum); - StrBuf_ServGetln(Buf); - if (GetServerStatus(Buf, NULL) != 6) { - convenience_page("770000", "Error", &(ChrPtr(Buf)[4])); + + Msg = (message_summary *) malloc(sizeof(message_summary)); + memset(Msg, 0, sizeof(message_summary)); + Msg->msgnum = msgnum; + VCMime = load_vcard(Msg); + if (VCMime == NULL) { + convenience_page("770000", _("Error"), "");///TODO: important message + DestroyMessageSummary(Msg); return; } - - StrBufCutLeft(Buf, 4); - total_len = StrBufExtract_long(Buf, 0, '|'); - - StrBuf_ServGetBLOBBuffered(Buf, total_len); - v = VCardLoad(Buf); + v = VCardLoad(VCMime->Data); } else { v = VCardLoad(VCAtt->Data); @@ -1063,6 +1055,8 @@ void do_edit_vcard(long msgnum, char *partnum, wprintf("\n"); do_template("endbox", NULL); wDumpContent(1); + if (Msg != NULL) + DestroyMessageSummary(Msg); } @@ -1225,7 +1219,7 @@ void display_vcard_photo_img(void) const char *contentType; wcsession *WCC = WC; - msgnum = StrTol(WCC->UrlFragment2); + msgnum = StrBufExtract_long(WCC->Hdr->HR.ReqLine, 0, '/'); vcard = load_mimepart(msgnum,"1"); v = VCardLoad(vcard);