/* * print a list of addresses; * each address is printed as '(' personalName AtDomainList mboxName hostName ')' * the AtDomainList is always NIL */ int Bimapaddr(Biobuf *b, MAddr *a) { char *host, *sep; int n; if(a == nil) return Bprint(b, "NIL"); n = Bputc(b, '('); sep = ""; for(; a != nil; a = a->next) { n += Bprint(b, "%s(", sep); n += Bimapstr(b, a->personal); n += Bprint(b," NIL "); n += Bimapstr(b, a->box); n += Bputc(b, ' '); /* * can't send NIL as hostName, since that is code for a group */ host = a->host; if(host == nil) host = ""; n += Bimapstr(b, host); n += Bputc(b, ')'); sep = " "; } n += Bputc(b, ')'); return n; }
void fetchEnvelope(Msg *m) { Tm tm; Bputc(&bout, '('); Brfc822date(&bout, date2tm(&tm, m->info[IDate])); Bputc(&bout, ' '); Bimapstr(&bout, m->info[ISubject]); Bputc(&bout, ' '); Bimapaddr(&bout, m->from); Bputc(&bout, ' '); Bimapaddr(&bout, m->sender); Bputc(&bout, ' '); Bimapaddr(&bout, m->replyTo); Bputc(&bout, ' '); Bimapaddr(&bout, m->to); Bputc(&bout, ' '); Bimapaddr(&bout, m->cc); Bputc(&bout, ' '); Bimapaddr(&bout, m->bcc); Bputc(&bout, ' '); Bimapstr(&bout, m->info[IInReplyTo]); Bputc(&bout, ' '); Bimapstr(&bout, m->info[IMessageId]); Bputc(&bout, ')'); }
int Brfc822date(Biobuf *b, Tm *tm) { char buf[64]; if(tm == nil) tm = localtime(time(nil)); rfc822date(buf, sizeof(buf), tm); return Bimapstr(b, buf); }
/* * common part of bodystructure extensions */ void fetchStructExt(Header *h) { Bputc(&bout, ' '); if(h->disposition != nil) { Bputc(&bout, '('); Bimapstr(&bout, h->disposition->s); Bputc(&bout, ' '); BimapMimeParams(&bout, h->disposition->next); Bputc(&bout, ')'); } else Bprint(&bout, "NIL"); Bputc(&bout, ' '); if(h->language != nil) { if(h->language->next != nil) BimapMimeParams(&bout, h->language->next); else Bimapstr(&bout, h->language->s); } else Bprint(&bout, "NIL"); }
int BimapMimeParams(Biobuf *b, MimeHdr *mh) { char *sep; int n; if(mh == nil) return Bprint(b, "NIL"); n = Bputc(b, '('); sep = ""; for(; mh != nil; mh = mh->next) { n += Bprint(b, sep); n += Bimapstr(b, mh->s); n += Bputc(b, ' '); n += Bimapstr(b, mh->t); sep = " "; } n += Bputc(b, ')'); return n; }
int BSList(Biobuf *b, SList *sl, char *sep) { char *s; int n; s = ""; n = 0; for(; sl != nil; sl = sl->next){ n += Bprint(b, "%s", s); n += Bimapstr(b, sl->s); s = sep; } return n; }
void fetchBodyStruct(Msg *m, Header *h, int extensions) { Msg *k; ulong len; if(msgIsMulti(h)) { Bputc(&bout, '('); for(k = m->kids; k != nil; k = k->next) fetchBodyStruct(k, &k->mime, extensions); Bputc(&bout, ' '); Bimapstr(&bout, h->type->t); if(extensions) { Bputc(&bout, ' '); BimapMimeParams(&bout, h->type->next); fetchStructExt(h); } Bputc(&bout, ')'); return; } Bputc(&bout, '('); if(h->type != nil) { Bimapstr(&bout, h->type->s); Bputc(&bout, ' '); Bimapstr(&bout, h->type->t); Bputc(&bout, ' '); BimapMimeParams(&bout, h->type->next); } else Bprint(&bout, "\"text\" \"plain\" NIL"); Bputc(&bout, ' '); if(h->id != nil) Bimapstr(&bout, h->id->s); else Bprint(&bout, "NIL"); Bputc(&bout, ' '); if(h->description != nil) Bimapstr(&bout, h->description->s); else Bprint(&bout, "NIL"); Bputc(&bout, ' '); if(h->encoding != nil) Bimapstr(&bout, h->encoding->s); else Bprint(&bout, "NIL"); /* * this is so strange: return lengths for a body[text] response, * except in the case of a multipart message, when return lengths for a body[] response */ len = m->size; if(h == &m->mime) len += m->head.size; Bprint(&bout, " %lud", len); len = m->lines; if(h == &m->mime) len += m->head.lines; if(h->type == nil || cistrcmp(h->type->s, "text") == 0) { Bprint(&bout, " %lud", len); } else if(msgIsRfc822(h)) { Bputc(&bout, ' '); k = m; if(h != &m->mime) k = m->kids; if(k == nil) Bprint(&bout, "(NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL) (\"text\" \"plain\" NIL NIL NIL NIL 0 0) 0"); else { fetchEnvelope(k); Bputc(&bout, ' '); fetchBodyStruct(k, &k->head, extensions); Bprint(&bout, " %lud", len); } } if(extensions) { Bputc(&bout, ' '); /* * don't have the md5 laying around, * since the header & body have added newlines. */ Bprint(&bout, "NIL"); fetchStructExt(h); } Bputc(&bout, ')'); }