File: rfc2045decodemimesection.c

package info (click to toggle)
maildrop 2.9.3-2.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 13,104 kB
  • sloc: ansic: 26,822; cpp: 9,085; sh: 4,868; makefile: 753; perl: 94
file content (47 lines) | stat: -rw-r--r-- 1,232 bytes parent folder | download | duplicates (17)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
** Copyright 2000-2011 Double Precision, Inc.  See COPYING for
** distribution information.
*/

#include "rfc2045_config.h"
#include	"rfc2045.h"
#include	"rfc2045src.h"
#include	<stdio.h>
#include	<unistd.h>


/*
** This function is used to decode MIME section content, and pass it to
** a handler function.  It's basically a wrapper around rfc2045_cdecode
** functions.
*/

int rfc2045_decodemimesection(struct rfc2045src *src, struct rfc2045 *rfc,
			      int (*handler)(const char *, size_t, void *),
			      void *voidarg)
{
	off_t	start_pos, end_pos, start_body;
	char	buf[BUFSIZ];
	ssize_t	cnt;
	off_t	dummy;
	int	rc;

	rfc2045_mimepos(rfc, &start_pos, &end_pos, &start_body,
		&dummy, &dummy);
	if (SRC_SEEK(src, start_body) == (off_t)-1) return (-1);

        rfc2045_cdecode_start(rfc, handler, voidarg);

        while (start_body < end_pos)
        {
                cnt=sizeof(buf);
                if (cnt > end_pos-start_body)
                        cnt=end_pos-start_body;
                cnt=SRC_READ(src, buf, cnt);
                if (cnt <= 0)   break;
                if ((rc=rfc2045_cdecode(rfc, buf, cnt)) != 0)
			return (rc);
		start_body += cnt;
        }
        return (rfc2045_cdecode_end(rfc));
}