Back to index

courier  0.68.2
rfc2045decodemimesection.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 2000-2011 Double Precision, Inc.  See COPYING for
00003 ** distribution information.
00004 */
00005 
00006 #include "rfc2045_config.h"
00007 #include      "rfc2045.h"
00008 #include      "rfc2045src.h"
00009 #include      <stdio.h>
00010 #include      <unistd.h>
00011 
00012 
00013 /*
00014 ** This function is used to decode MIME section content, and pass it to
00015 ** a handler function.  It's basically a wrapper around rfc2045_cdecode
00016 ** functions.
00017 */
00018 
00019 int rfc2045_decodemimesection(struct rfc2045src *src, struct rfc2045 *rfc,
00020                            int (*handler)(const char *, size_t, void *),
00021                            void *voidarg)
00022 {
00023        off_t  start_pos, end_pos, start_body;
00024        char   buf[BUFSIZ];
00025        ssize_t       cnt;
00026        off_t  dummy;
00027        int    rc;
00028 
00029        rfc2045_mimepos(rfc, &start_pos, &end_pos, &start_body,
00030               &dummy, &dummy);
00031        if (SRC_SEEK(src, start_body) == (off_t)-1) return (-1);
00032 
00033         rfc2045_cdecode_start(rfc, handler, voidarg);
00034 
00035         while (start_body < end_pos)
00036         {
00037                 cnt=sizeof(buf);
00038                 if (cnt > end_pos-start_body)
00039                         cnt=end_pos-start_body;
00040                 cnt=SRC_READ(src, buf, cnt);
00041                 if (cnt <= 0)   break;
00042                 if ((rc=rfc2045_cdecode(rfc, buf, cnt)) != 0)
00043                      return (rc);
00044               start_body += cnt;
00045         }
00046         return (rfc2045_cdecode_end(rfc));
00047 }