2 * Copyright notice from original mutt:
3 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
5 * This file is part of mutt-ng, see http://www.muttng.org/.
6 * It's licensed under the GNU General Public License,
7 * please see the file GPL in the top level source directory.
20 #include "lib/debug.h"
22 static void state_prefix_put (const char *d, size_t dlen, STATE * s)
26 state_prefix_putc (*d++, s);
28 fwrite (d, dlen, 1, s->fpout);
31 void mutt_convert_to_state (iconv_t cd, char *bufi, size_t * l, STATE * s)
39 if (cd != (iconv_t) (-1)) {
40 ob = bufo, obl = sizeof (bufo);
41 my_iconv(cd, 0, 0, &ob, &obl);
43 state_prefix_put (bufo, ob - bufo, s);
45 if (Quotebuf[0] != '\0')
46 state_prefix_putc ('\n', s);
50 if (cd == (iconv_t) (-1)) {
51 state_prefix_put (bufi, *l, s);
58 ob = bufo, obl = sizeof (bufo);
59 mutt_iconv (cd, &ib, &ibl, &ob, &obl, 0, "?");
62 state_prefix_put (bufo, ob - bufo, s);
64 memmove (bufi, ib, ibl);
68 void state_prefix_putc (char c, STATE * s)
70 if (s->flags & M_PENDINGPREFIX) {
73 i = m_strlen(Quotebuf);
76 if (i == sizeof (Quotebuf) - 1 || c == '\n') {
77 char buf[2 * SHORT_STRING];
78 int j = 0, offset = 0;
81 unsigned char save = '\0';
84 state_reset_prefix (s);
86 ((regex_t *) QuoteRegexp.rx, &Quotebuf[offset], 1, pmatch,
88 offset += pmatch->rm_eo;
90 if (!option (OPTQUOTEEMPTY) && Quotebuf[offset] == '\n') {
94 else if (!option (OPTTEXTFLOWED) && option (OPTQUOTEQUOTED) && offset) {
95 for (i = 0; i < offset; i++)
96 if (Quotebuf[i] != ' ')
98 strncpy (buf, Quotebuf, j + 1);
99 strcpy (buf + j + 1, Quotebuf + j);
102 snprintf (buf, sizeof (buf), "%s%s", NONULL (s->prefix), Quotebuf);
105 if (m_strlen(buf) >= 2) {
106 save = buf[m_strlen(buf) - 1];
107 buf[m_strlen(buf) - 1] = '\0';
108 debug_print (2, ("buf = '%s'\n", buf));
109 buf[m_strlen(buf)] = save;
120 state_set_prefix (s);
125 int state_printf (STATE * s, const char *fmt, ...)
131 rv = vfprintf (s->fpout, fmt, ap);
137 void state_mark_attach (STATE * s)
139 if ((s->flags & M_DISPLAY) && !m_strcmp(Pager, "builtin"))
140 state_puts (AttachmentMarker, s);
143 void state_attach_puts (const char *t, STATE * s)
146 state_mark_attach (s);
149 if (*t++ == '\n' && *t)
151 state_mark_attach (s);