"
- "
\n");
- do_template("endbox", NULL);
wDumpContent(1);
+ if (Msg != NULL) {
+ DestroyMessageSummary(Msg);
+ }
}
-/**
+/*
* commit the edits to the citadel server
*/
void edit_vcard(void) {
@@ -1006,161 +697,505 @@ void edit_vcard(void) {
msgnum = lbstr("msgnum");
partnum = bstr("partnum");
- do_edit_vcard(msgnum, partnum, "", NULL);
+ do_edit_vcard(msgnum, partnum, NULL, NULL, "", NULL);
}
-
-
-/**
+/*
* parse edited vcard from the browser
*/
void submit_vcard(void) {
struct vCard *v;
char *serialized_vcard;
- char buf[SIZ];
- int i;
+ StrBuf *Buf;
+ const StrBuf *ForceRoom;
+ HashList* postVcard;
+ HashPos *it, *itSub;
+ const char *Key;
+ long len;
+ void *pv;
+ StrBuf *SubStr;
+ const StrBuf *s;
+ const char *Pos = NULL;
if (!havebstr("ok_button")) {
- readloop(readnew);
+ readloop(readnew, eUseDefault);
return;
}
if (havebstr("force_room")) {
- gotoroom(bstr("force_room"));
+ ForceRoom = sbstr("force_room");
+ if (gotoroom(ForceRoom) != 200) {
+ AppendImportantMessage(_("Unable to enter the room to save your message"), -1);
+ AppendImportantMessage(HKEY(": "));
+ AppendImportantMessage(SKEY(ForceRoom));
+ AppendImportantMessage(HKEY("; "));
+ AppendImportantMessage(_("Aborting."), -1);
+
+ if (!strcmp(bstr("return_to"), "select_user_to_edit")) {
+ select_user_to_edit(NULL);
+ }
+ else if (!strcmp(bstr("return_to"), "do_welcome")) {
+ do_welcome();
+ }
+ else if (!IsEmptyStr(bstr("return_to"))) {
+ http_redirect(bstr("return_to"));
+ }
+ else {
+ readloop(readnew, eUseDefault);
+ }
+ return;
+ }
}
- sprintf(buf, "ENT0 1|||4||");
- serv_puts(buf);
- serv_getln(buf, sizeof buf);
- if (buf[0] != '4') {
+ postVcard = getSubStruct(HKEY("VC"));
+ if (postVcard == NULL) {
+ AppendImportantMessage(_("An error has occurred."), -1);
+ edit_vcard();
+ return;/*/// more details*/
+ }
+
+ Buf = NewStrBuf();
+ serv_write(HKEY("ENT0 1|||4\n"));
+ if (!StrBuf_ServGetln(Buf) && (GetServerStatus(Buf, NULL) != 4))
+ {
edit_vcard();
return;
}
-
- /** Make a vCard structure out of the data supplied in the form */
-
- snprintf(buf, sizeof buf, "begin:vcard\r\n%s\r\nend:vcard\r\n",
- bstr("extrafields")
+
+ /* Make a vCard structure out of the data supplied in the form */
+ StrBufPrintf(Buf, "begin:vcard\r\n%s\r\nend:vcard\r\n",
+ bstr("extrafields")
);
- v = vcard_load(buf); /** Start with the extra fields */
+ v = VCardLoad(Buf); /* Start with the extra fields */
if (v == NULL) {
- safestrncpy(WC->ImportantMessage,
- _("An error has occurred."),
- sizeof WC->ImportantMessage
- );
+ AppendImportantMessage(_("An error has occurred."), -1);
edit_vcard();
+ FreeStrBuf(&Buf);
return;
}
- snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s",
- bstr("lastname"),
- bstr("firstname"),
- bstr("middlename"),
- bstr("prefix"),
- bstr("suffix") );
- vcard_add_prop(v, "n", buf);
-
- vcard_add_prop(v, "title", bstr("title"));
- vcard_add_prop(v, "fn", bstr("fullname"));
- vcard_add_prop(v, "org", bstr("org"));
-
- snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s;%s;%s",
- bstr("pobox"),
- bstr("extadr"),
- bstr("street"),
- bstr("city"),
- bstr("state"),
- bstr("zipcode"),
- bstr("country") );
- vcard_add_prop(v, "adr", buf);
-
- vcard_add_prop(v, "tel;home", bstr("hometel"));
- vcard_add_prop(v, "tel;work", bstr("worktel"));
- vcard_add_prop(v, "tel;fax", bstr("faxtel"));
- vcard_add_prop(v, "tel;cell", bstr("mobiletel"));
- vcard_add_prop(v, "email;internet", bstr("primary_inetemail"));
-
- for (i=0; i
Sub != NULL){
+ vcField *Sub;
+ FlushStrBuf(SubStr);
+ itSub = GetNewHashPos(DefineToToken, 0);
+ while (GetNextHashPos(DefineToToken, itSub, &len, &Key, &pv) &&
+ (pv != NULL))
+ {
+ Sub = (vcField*) pv;
+ if (Sub->parentCVal == t->cval) {
+ if (StrLength(SubStr) > 0)
+ StrBufAppendBufPlain(SubStr, HKEY(";"), 0);
+
+
+
+ blen = snprintf(buf, sizeof(buf), "%ld", Sub->cval);
+ s = SSubBstr(postVcard, buf, blen);
+
+ if ((s != NULL) && (StrLength(s) > 0)) {
+ /// todo: utf8 qp
+ StrBufAppendBuf(SubStr, s, 0);
+ }
+ }
+ }
+ if (StrLength(SubStr) > 0) {
+ vcard_add_prop(v, t->STR.Key, ChrPtr(SubStr));
+ }
+ DeleteHashPos(&itSub);
+ }
+ else if (t->parentCVal == 0) {
+ blen = snprintf(buf, sizeof(buf), "%ld", t->cval);
+ s = SSubBstr(postVcard, buf, blen);
+
+ if ((s != NULL) && (StrLength(s) > 0)) {
+ vcard_add_prop(v, t->STR.Key, ChrPtr(s));
+ }
}
}
+ DeleteHashPos(&it);
+
+ s = sbstr("other_inetemail");
+ if (StrLength(s) > 0) {
+ FlushStrBuf(SubStr);
+ while (StrBufSipLine(SubStr, s, &Pos), ((Pos!=StrBufNOTNULL) && (Pos!=NULL)) ) {
+ if (StrLength(SubStr) > 0) {
+ vcard_add_prop(v, "email;internet", ChrPtr(SubStr));
+ }
+ }
+ }
+
+ FreeStrBuf(&SubStr);
+
serialized_vcard = vcard_serialize(v);
vcard_free(v);
if (serialized_vcard == NULL) {
- safestrncpy(WC->ImportantMessage,
- _("An error has occurred."),
- sizeof WC->ImportantMessage
- );
+ AppendImportantMessage(_("An error has occurred."), -1);
edit_vcard();
+ FreeStrBuf(&Buf);
return;
}
- serv_puts("Content-type: text/x-vcard; charset=UTF-8");
- serv_puts("");
+ printf("%s", serialized_vcard);
+ serv_write(HKEY("Content-type: text/x-vcard; charset=UTF-8\n"));
+ serv_write(HKEY("\n"));
serv_printf("%s\r\n", serialized_vcard);
- serv_puts("000");
+ serv_write(HKEY("000\n"));
free(serialized_vcard);
if (!strcmp(bstr("return_to"), "select_user_to_edit")) {
- select_user_to_edit(NULL, NULL);
+ select_user_to_edit(NULL);
}
else if (!strcmp(bstr("return_to"), "do_welcome")) {
do_welcome();
}
+ else if (!IsEmptyStr(bstr("return_to"))) {
+ http_redirect(bstr("return_to"));
+ }
else {
- readloop(readnew);
+ readloop(readnew, eUseDefault);
}
+ FreeStrBuf(&Buf);
}
+/******************************************************************************
+ * Render Addressbooks *
+ ******************************************************************************/
+typedef struct _vcardview_struct {
+ long is_singlecard;
+ HashList *addrbook;
-/*
- * Extract an embedded photo from a vCard for display on the client
- */
-void display_vcard_photo_img(void)
+} vcardview_struct;
+
+int vcard_GetParamsGetServerCall(SharedMessageStatus *Stat,
+ void **ViewSpecific,
+ long oper,
+ char *cmd,
+ long len,
+ char *filter,
+ long flen)
+{
+ vcardview_struct *VS;
+
+ VS = (vcardview_struct*) malloc (sizeof(vcardview_struct));
+ memset(VS, 0, sizeof(vcardview_struct));
+ *ViewSpecific = (void*)VS;
+
+ VS->is_singlecard = ibstr("is_singlecard");
+ if (VS->is_singlecard != 1) {
+ VS->addrbook = NewHash(0, NULL);
+ if (oper == do_search) {
+ snprintf(cmd, len, "MSGS SEARCH|%s", bstr("query"));
+ }
+ else {
+ strcpy(cmd, "MSGS ALL");
+ }
+ Stat->maxmsgs = 9999999;
+ }
+ return 200;
+}
+
+int vcard_LoadMsgFromServer(SharedMessageStatus *Stat,
+ void **ViewSpecific,
+ message_summary* Msg,
+ int is_new,
+ int i)
{
- long msgnum = 0L;
- char *vcard;
- struct vCard *v;
- char *photosrc;
- const char *contentType;
wcsession *WCC = WC;
+ WCTemplputParams *TP = NULL;
+ WCTemplputParams SubTP;
+ vcardview_struct *VS;
+ wc_mime_attachment *VCMime = NULL;
+ struct vCard *v;
+ addrbookent* abEntry;
+
+ VS = (vcardview_struct*) *ViewSpecific;
+
+ VCMime = load_vcard(Msg);
+ if (VCMime == NULL)
+ return 0;
- msgnum = StrTol(WCC->UrlFragment2);
+ v = VCardLoad(VCMime->Data);
+
+ if (v == NULL) return 0;
+
+ abEntry = (addrbookent*) malloc(sizeof(addrbookent));
+ memset(abEntry, 0, sizeof(addrbookent));
+ abEntry->name = NewStrBuf();
+ abEntry->VC = NewHash(0, lFlathash);
+ abEntry->ab_msgnum = Msg->msgnum;
+
+ parse_vcard(WCC->WBuf, v, abEntry->VC, VCMime);
+
+ memset(&SubTP, 0, sizeof(WCTemplputParams));
+ StackContext(TP, &SubTP, abEntry, CTX_VCARD, 0, NULL);
+
+ // No, don't display the name, it just shits all over the screen
+ // DoTemplate(HKEY("vcard_list_name"), WCC->WBuf, &SubTP);
+
+ UnStackContext(&SubTP);
+
+ if (StrLength(abEntry->name) == 0) {
+ StrBufPlain(abEntry->name, _("(no name)"), -1);
+ }
+
+ syslog(LOG_DEBUG, "abEntry->name : %s", ChrPtr(abEntry->name));
+
+ vcard_free(v);
- vcard = load_mimepart(msgnum,"1");
- v = vcard_load(vcard);
+ Put(VS->addrbook, SKEY(abEntry->name), abEntry, deleteAbEnt);
+ return 0;
+}
+
+
+/*
+ * Render the address book using info we gathered during the scan
+ *
+ * addrbook the addressbook to render
+ * num_ab the number of the addressbook
+ */
+static int NAMESPERPAGE = 60;
+void do_addrbook_view(vcardview_struct* VS) {
+ long i = 0;
+ int num_pages = 0;
+ int tabfirst = 0;
+ int tablast = 0;
+ StrBuf **tablabels;
+ int num_ab = GetCount(VS->addrbook);
+ HashList *headlines;
+ wcsession *WCC = WC;
+
+ WCTemplputParams *TP = NULL;
+ WCTemplputParams SubTP;
+
+ memset(&SubTP, 0, sizeof(WCTemplputParams));
- photosrc = vcard_get_prop(v, "PHOTO", 1,0,0);
- FlushStrBuf(WCC->WBuf);
- StrBufAppendBufPlain(WCC->WBuf, photosrc, -1, 0);
- if (StrBufDecodeBase64(WCC->WBuf) <= 0) {
- FlushStrBuf(WCC->WBuf);
-
- hprintf("HTTP/1.1 500 %s\n","Unable to get photo");
- output_headers(0, 0, 0, 0, 0, 0);
- hprintf("Content-Type: text/plain\r\n");
- wprintf(_("Could Not decode vcard photo\n"));
- end_burst();
+ if (num_ab == 0) {
+ do_template("vcard_list_empty");
return;
}
- contentType = GuessMimeType(ChrPtr(WCC->WBuf), StrLength(WCC->WBuf));
- http_transmit_thing(contentType, 0);
- free(v);
- free(photosrc);
+
+ if (num_ab > 1) {
+ SortByHashKey(VS->addrbook, 1);
+ }
+
+ num_pages = (GetCount(VS->addrbook) / NAMESPERPAGE) + 1;
+
+ tablabels = malloc(num_pages * sizeof (StrBuf *));
+ if (tablabels == NULL) {
+ return;
+ }
+
+ headlines = NewHash(0, lFlathash);
+ for (i=0; i (num_ab - 1)) tablast = (num_ab - 1);
+
+ headline = NewStrBufPlain(NULL, StrLength(v1) + StrLength(v2) + 10);
+ if (GetHashAt(VS->addrbook, tabfirst, &hklen1, &c1, &v1)) {
+ a1 = (addrbookent*) v1;
+ StrBufAppendBuf(headline, a1->name, 0);
+ StrBuf_Utf8StrCut(headline, 3);
+ if (GetHashAt(VS->addrbook, tablast, &hklen2, &c2, &v2)) {
+
+ a2 = (addrbookent*) v2;
+ StrBufAppendBufPlain(headline, HKEY(" - "), 0);
+ StrBufAppendBuf(headline, a2->name, 0);
+ StrBuf_Utf8StrCut(headline, 9);
+ }
+ }
+ tablabels[i] = headline;
+ Put(headlines, LKEY(i), headline, HFreeStrBuf);
+ }
+ StrTabbedDialog(WC->WBuf, num_pages, tablabels);
+ StackContext(TP, &SubTP, VS->addrbook, CTX_VCARD_LIST, 0, NULL);
+
+ DoTemplate(HKEY("vcard_list"), WCC->WBuf, &SubTP);
+ UnStackContext(&SubTP);
+ DeleteHash(&headlines);
+ free(tablabels);
+ StrBufAppendBufPlain(WCC->WBuf, HKEY(" "), 0);/* closes: id=global */
+}
+
+
+
+int vcard_RenderView_or_Tail(SharedMessageStatus *Stat, void **ViewSpecific, long oper)
+{
+ const StrBuf *Mime;
+ vcardview_struct *VS;
+
+ VS = (vcardview_struct*) *ViewSpecific;
+ if (VS->is_singlecard) {
+ read_message(WC->WBuf, HKEY("view_message"), lbstr("startmsg"), NULL, &Mime, NULL);
+ }
+ else {
+ do_addrbook_view(VS); /* Render the address book */
+ }
+ return 0;
+}
+
+int vcard_Cleanup(void **ViewSpecific)
+{
+ vcardview_struct *VS;
+
+ VS = (vcardview_struct*) *ViewSpecific;
+ wDumpContent(1);
+ if ((VS != NULL) && (VS->addrbook != NULL)) {
+ DeleteHash(&VS->addrbook);
+ }
+ if (VS != NULL) {
+ free(VS);
+ }
+
+ return 0;
+}
+
+void render_MIME_VCard(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
+{
+ wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
+ wcsession *WCC = WC;
+ if (StrLength(Mime->Data) == 0) {
+ MimeLoadData(Mime);
+ }
+ if (StrLength(Mime->Data) > 0) {
+ struct vCard *v;
+ StrBuf *Buf;
+
+ Buf = NewStrBuf();
+ /** If it's my vCard I can edit it */
+ if ( (!strcasecmp(ChrPtr(WCC->CurRoom.name), USERCONFIGROOM))
+ || ((StrLength(WCC->CurRoom.name) > 11) &&
+ (!strcasecmp(&(ChrPtr(WCC->CurRoom.name)[11]), USERCONFIGROOM)))
+ || (WCC->CurRoom.view == VIEW_ADDRESSBOOK)
+ ) {
+ StrBufAppendPrintf(Buf, "