view f-demime/b2q_in.c @ 2:1857d0d5a7bd

f-demime: fix parsing of Content-* headers
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 06 May 2023 06:33:26 +0000
parents 7e0d08176f32
children
line wrap: on
line source

/*
 * This module implements the input side of base64-to-QP conversion.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "defs.h"

extern void (*dec_outf)();
extern FILE *tempfile;

static int cr_state;

static void
output_func(ch)
{
	if (cr_state) {
		cr_state = 0;
		if (ch == '\n') {
			putc('\n', tempfile);
			return;
		} else
			putc('\r', tempfile);
	}
	if (ch == '\r')
		cr_state = 1;
	else
		putc(ch, tempfile);
}

void
b2q_conv_init()
{
	dec_outf = output_func;
	cr_state = 0;
}

void
b2q_conv_finish()
{
	if (cr_state)
		putc('\r', tempfile);
}