Encode text as quoted printable.
150{
151 int c, linelen = 0;
152 char line[77] = { 0 };
153
155 {
156
157 if ((linelen == 76) && ((istext && (c != '\n')) || !istext))
158 {
159
160
161
162 if (line[linelen - 3] == '=')
163 {
164 line[linelen - 3] = 0;
165 fputs(line, fp_out);
166 fputs("=\n", fp_out);
167 line[linelen] = 0;
168 line[0] = '=';
169 line[1] = line[linelen - 2];
170 line[2] = line[linelen - 1];
171 linelen = 3;
172 }
173 else
174 {
175 char savechar = line[linelen - 1];
176 line[linelen - 1] = '=';
177 line[linelen] = 0;
178 fputs(line, fp_out);
179 fputc('\n', fp_out);
180 line[0] = savechar;
181 linelen = 1;
182 }
183 }
184
185
187 {
189 linelen = 6;
190 }
192 {
194 linelen = 6;
195 }
196 else if ((linelen == 1) && (line[0] == '.'))
197 {
199 linelen = 3;
200 }
201
202 if ((c == '\n') && istext)
203 {
204
205 if ((linelen > 0) && ((line[linelen - 1] == ' ') || (line[linelen - 1] == '\t')))
206 {
207 if (linelen < 74)
208 {
209 sprintf(line + linelen - 1, "=%2.2X", (unsigned char) line[linelen - 1]);
210 fputs(line, fp_out);
211 }
212 else
213 {
214 int savechar2 = line[linelen - 1];
215
216 line[linelen - 1] = '=';
217 line[linelen] = 0;
218 fputs(line, fp_out);
219 fprintf(fp_out, "\n=%2.2X", (unsigned char) savechar2);
220 }
221 }
222 else
223 {
224 line[linelen] = 0;
225 fputs(line, fp_out);
226 }
227 fputc('\n', fp_out);
228 linelen = 0;
229 }
230 else if ((c != 9) && ((c < 32) || (c > 126) || (c == '=')))
231 {
232
233
234 if (linelen > 73)
235 {
236 line[linelen++] = '=';
237 line[linelen] = 0;
238 fputs(line, fp_out);
239 fputc('\n', fp_out);
240 linelen = 0;
241 }
242 sprintf(line + linelen, "=%2.2X", (unsigned char) c);
243 linelen += 3;
244 }
245 else
246 {
247
248
249 line[linelen++] = c;
250 }
251 }
252
253
254 if (linelen > 0)
255 {
256 if ((line[linelen - 1] == ' ') || (line[linelen - 1] == '\t'))
257 {
258
259 if (linelen < 74)
260 {
261 sprintf(line + linelen - 1, "=%2.2X", (unsigned char) line[linelen - 1]);
262 }
263 else
264 {
265 char savechar = line[linelen - 1];
266 line[linelen - 1] = '=';
267 line[linelen] = 0;
268 fputs(line, fp_out);
269 fputc('\n', fp_out);
270 snprintf(line, sizeof(line), "=%2.2X", (unsigned char) savechar);
271 }
272 }
273 else
274 {
275 line[linelen] = 0;
276 }
277 fputs(line, fp_out);
278 }
279}
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)