[2023-08-23 14:29] Philipp <philipp+...@bureaucracy.de> > [2023-08-20 22:14] David Levine <levin...@acm.org> > > Ken Hornstein wrote: > > > > > [Phillip wrote:] > > > >Or in output_headers(). I'm not sure if there an extra options would be > > > >required. > > > > > > That is one option. Another is that repl(1) could do a better job; I > > > suppose that is the fault of mhl. > > > > [...] > > > > I think that output_headers() is the right place. It's the only > > place where header fields are output. > > > > [...] > > [...] > > I'll try to implement a corrent fold funktion on the weekend.
I found a bit time to implement this today. Just the fold() fuction not the integration in output_headers(). Philipp > Philipp > > [0] I don't know if this is an issue in the context of ical > > > David >
#include "h/mh.h" #include "h/mime.h" #include <stdio.h> void fold(FILE *restrict stream, const char *restrict name, const char *restrict body) { const char *restrict body_next; const char *restrict wsp; const char *restrict wsp_next; const bool crlf = strchr(body, '\r'); size_t namelen = fprintf(stream, "%s:", name); if (namelen >= MAXTEXTPERLN) { if (crlf) { fputs("\r\n ", stream); } else { fputs("\n ", stream); } namelen = 0; } while (*body) { body_next = strchr(body, '\n'); if ((unsigned long) (body_next - body) <= MAXTEXTPERLN - namelen) { fwrite(body, 1, body_next - body + 1, stream); namelen = 0; body = body_next + 1; continue; } wsp = strpbrk(body, " \t"); /* if now whitespace is in the current line just print the curret line as is */ if (!wsp || wsp > body_next) { fwrite(body, 1, body_next - body + 1, stream); namelen = 0; body = body_next + 1; continue; } while ((unsigned long)(wsp - body) <= MAXTEXTPERLN - namelen) { wsp_next = strpbrk(wsp, " \t"); if (!wsp_next) { break; } if (wsp_next > body_next) { break; } wsp = wsp_next; } fwrite(body, 1, wsp - body, stream); if (crlf) { fputs("\r\n", stream); } else { fputs("\n", stream); } fputc(*wsp, stream); namelen = 1; body = wsp + 1; } }