summaryrefslogtreecommitdiffstats
path: root/rfc2045/rfc2045decodemimesection.c
diff options
context:
space:
mode:
authorSam Varshavchik2013-08-19 16:39:41 -0400
committerSam Varshavchik2013-08-25 14:43:51 -0400
commit9c45d9ad13fdf439d44d7443ae75da15ea0223ed (patch)
tree7a81a04cb51efb078ee350859a64be2ebc6b8813 /rfc2045/rfc2045decodemimesection.c
parenta9520698b770168d1f33d6301463bb70a19655ec (diff)
downloadcourier-libs-9c45d9ad13fdf439d44d7443ae75da15ea0223ed.tar.bz2
Initial checkin
Imported from subversion report, converted to git. Updated all paths in scripts and makefiles, reflecting the new directory hierarchy.
Diffstat (limited to 'rfc2045/rfc2045decodemimesection.c')
-rw-r--r--rfc2045/rfc2045decodemimesection.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/rfc2045/rfc2045decodemimesection.c b/rfc2045/rfc2045decodemimesection.c
new file mode 100644
index 0000000..03ce386
--- /dev/null
+++ b/rfc2045/rfc2045decodemimesection.c
@@ -0,0 +1,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));
+}