+ readloop(readnew, eUseDefault);
+ }
+ FreeStrBuf(&Buf);
+}
+
+
+
+typedef struct _vcardview_struct {
+ long is_singlecard;
+ HashList *addrbook;
+
+} 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)
+{
+ 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;
+
+ 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(WC->WBuf, v, abEntry->VC, VCMime);
+
+ display_one_vcard(abEntry->name, abEntry, HKEY("vcard_list_name"));
+
+ if (StrLength(abEntry->name) == 0) {
+ StrBufPlain(abEntry->name, _("(no name)"), -1);
+ }
+
+ vcard_free(v);
+
+ 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 displayed = 0;
+ int bg = 0;
+ int num_pages = 0;
+ int tabfirst = 0;
+ int tablast = 0;
+ int page = 0;
+ const StrBuf **tablabels;
+ int num_ab = GetCount(VS->addrbook);
+ HashList *headlines;
+ HashPos *it;
+ wcsession *WCC = WC;
+
+ WCTemplputParams *TP = NULL;
+ WCTemplputParams SubTP;
+
+ memset(&SubTP, 0, sizeof(WCTemplputParams));
+
+ if (num_ab == 0) {
+ do_template("vcard_list_empty");
+ return;
+ }
+
+ if (num_ab > 1) {
+ ///SortByHashKey(VS->addrbook, 0);
+ }
+
+ 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_pages; ++i) {
+ void *v1 = NULL;
+ void *v2 = NULL;
+ long hklen1, hklen2;
+ const char *c1, *c2;
+ StrBuf *headline;
+ addrbookent *a1, *a2;
+
+ tabfirst = i * NAMESPERPAGE;
+ tablast = tabfirst + NAMESPERPAGE - 1;
+ if (tablast > (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);
+
+ if (GetHashAt(VS->addrbook, tablast, &hklen2, &c2, &v2)) {
+
+ a2 = (addrbookent*) v2;
+ StrBufAppendBufPlain(headline, HKEY(" - "), 0);
+ StrBufAppendBuf(headline, a2->name, 0);
+ }
+ }
+ tablabels[i] = headline;
+ Put(headlines, LKEY(i), headline, HFreeStrBuf);
+ }
+ StrTabbedDialog(WC->WBuf, num_pages, tablabels);
+ page = (-1);
+
+
+ StackContext(TP, &SubTP, VS->addrbook, CTX_VCARD_LIST, 0, NULL);
+
+ DoTemplate(HKEY("vcard_list"), WCC->WBuf, &SubTP);
+ UnStackContext(&SubTP);
+/*
+ it = GetNewHashPos(VS->addrbook, 0);
+ for (i=0; i<num_ab; ++i) {
+ void *v;
+ long hklen;
+ const char *key;
+ addrbookent *abEnt;
+ GetNextHashPos(VS->addrbook, it, &hklen, &key, &v);
+ if (v == NULL)
+ continue;
+ abEnt = (addrbookent *) v;
+ if ((i / NAMESPERPAGE) != page) { / * New tab * /
+ page = (i / NAMESPERPAGE);
+ if (page > 0) {
+ do_template("vcard_list_section_end");
+ end_tab(page-1, num_pages);
+ }
+ begin_tab(page, num_pages);
+ do_template("vcard_list_section_start");
+ displayed = 0;
+ }
+
+ if ((displayed % 4) == 0) {
+ if (displayed > 0) {
+ do_template("vcard_list_row_end");
+ }
+ do_template("vcard_list_row_start");
+ bg = 1 - bg;
+ }
+
+
+ StackContext(TP, &SubTP, abEnt, CTX_VCARD, 0, NULL);
+
+ DoTemplate(HKEY("vcard_list_entry"), WCC->WBuf, &SubTP);
+ UnStackContext(&SubTP);
+
+ ++displayed;
+ }
+ DeleteHashPos(&it);
+*/
+ /* Placeholders for empty columns at end */
+ if ((num_ab % 4) != 0) {
+ for (i=0; i<(4-(num_ab % 4)); ++i) {
+ do_template("vcard_list_cell_end");
+ }
+ }
+
+ do_template("vcard_list_section_end");
+ end_tab((num_pages-1), num_pages);
+
+ begin_tab(num_pages, num_pages);
+ /* FIXME there ought to be something here */
+ end_tab(num_pages, num_pages);
+
+ DeleteHash(&headlines);
+ free(tablabels);
+ wDumpContent(1);
+}
+
+
+
+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);
+ 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, "<a href=\"edit_vcard?msgnum=%ld?partnum=%s\">",
+ Mime->msgnum, ChrPtr(Mime->PartNum));
+ StrBufAppendPrintf(Buf, "[%s]</a>", _("edit"));
+ }
+
+ /* In all cases, display the full card */
+
+ v = VCardLoad(Mime->Data);
+
+ if (v != NULL) {
+ HashList *VC;
+ addrbookent ab;
+ memset(&ab, 0, sizeof(addrbookent));
+
+ ab.VC = NewHash(0, lFlathash);
+ ab.ab_msgnum = Mime->msgnum;
+
+ parse_vcard(Target, v, VC, Mime);
+ display_one_vcard (Target, &ab, HKEY("vcard_msg_display"));
+ DeleteHash(&VC);
+
+ }
+ else {
+ StrBufPlain(Buf, _("failed to load vcard"), -1);
+ }
+ FreeStrBuf(&Mime->Data);
+ Mime->Data = Buf;