| 2107 | } |
| 2108 | |
| 2109 | void pp_email_subject(struct pretty_print_context *pp, |
| 2110 | const char **msg_p, |
| 2111 | struct strbuf *sb, |
| 2112 | const char *encoding, |
| 2113 | int need_8bit_cte) |
| 2114 | { |
| 2115 | static const int max_length = 78; /* per rfc2047 */ |
| 2116 | struct strbuf title; |
| 2117 | |
| 2118 | strbuf_init(&title, 80); |
| 2119 | *msg_p = format_subject(&title, *msg_p, |
| 2120 | pp->preserve_subject ? "\n" : " "); |
| 2121 | |
| 2122 | strbuf_grow(sb, title.len + 1024); |
| 2123 | fmt_output_email_subject(sb, pp->rev); |
| 2124 | if (pp->encode_email_headers && |
| 2125 | needs_rfc2047_encoding(title.buf, title.len)) |
| 2126 | add_rfc2047(sb, title.buf, title.len, |
| 2127 | encoding, RFC2047_SUBJECT); |
| 2128 | else |
| 2129 | strbuf_add_wrapped_bytes(sb, title.buf, title.len, |
| 2130 | -last_line_length(sb), 1, max_length); |
| 2131 | strbuf_addch(sb, '\n'); |
| 2132 | |
| 2133 | if (need_8bit_cte == 0) { |
| 2134 | int i; |
| 2135 | for (i = 0; i < pp->in_body_headers.nr; i++) { |
| 2136 | if (has_non_ascii(pp->in_body_headers.items[i].string)) { |
| 2137 | need_8bit_cte = 1; |
| 2138 | break; |
| 2139 | } |
| 2140 | } |
| 2141 | } |
| 2142 | |
| 2143 | if (need_8bit_cte > 0) { |
| 2144 | const char *header_fmt = |
| 2145 | "MIME-Version: 1.0\n" |
| 2146 | "Content-Type: text/plain; charset=%s\n" |
| 2147 | "Content-Transfer-Encoding: 8bit\n"; |
| 2148 | strbuf_addf(sb, header_fmt, encoding); |
| 2149 | } |
| 2150 | if (pp->after_subject) { |
| 2151 | strbuf_addstr(sb, pp->after_subject); |
| 2152 | } |
| 2153 | |
| 2154 | strbuf_addch(sb, '\n'); |
| 2155 | |
| 2156 | if (pp->in_body_headers.nr) { |
| 2157 | int i; |
| 2158 | for (i = 0; i < pp->in_body_headers.nr; i++) { |
| 2159 | strbuf_addstr(sb, pp->in_body_headers.items[i].string); |
| 2160 | free(pp->in_body_headers.items[i].string); |
| 2161 | } |
| 2162 | string_list_clear(&pp->in_body_headers, 0); |
| 2163 | strbuf_addch(sb, '\n'); |
| 2164 | } |
| 2165 | |
| 2166 | strbuf_release(&title); |
no test coverage detected