summaryrefslogtreecommitdiff
path: root/ext/mailparse/rfc2045cdecode.c
diff options
context:
space:
mode:
authorWez Furlong <wez@php.net>2001-05-20 11:11:28 +0000
committerWez Furlong <wez@php.net>2001-05-20 11:11:28 +0000
commit6468f8b492040c8e973608fa41c5c64a6e2434b2 (patch)
tree2d1737225dd746b4c20c0474598fca3f55c25c95 /ext/mailparse/rfc2045cdecode.c
parent83b18832aa9f252a8f9f47536867a982d143e030 (diff)
downloadphp-git-6468f8b492040c8e973608fa41c5c64a6e2434b2.tar.gz
Imported mailparse extension
@- New mailparse extension for parsing and manipulating MIME mail (Wez)
Diffstat (limited to 'ext/mailparse/rfc2045cdecode.c')
-rwxr-xr-xext/mailparse/rfc2045cdecode.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/ext/mailparse/rfc2045cdecode.c b/ext/mailparse/rfc2045cdecode.c
new file mode 100755
index 0000000000..971c59d77b
--- /dev/null
+++ b/ext/mailparse/rfc2045cdecode.c
@@ -0,0 +1,83 @@
+/* $Id$ */
+/*
+ ** Copyright 1998 - 1999 Double Precision, Inc. See COPYING for
+ ** distribution information.
+ */
+
+#include "php.h"
+#include "php_mailparse.h"
+
+
+static int op_func(int c, void *dat)
+{
+ unsigned char C = (unsigned char)c;
+ struct rfc2045 * p = (struct rfc2045*)dat;
+
+ (*p->udecode_func)(&C, 1, p->misc_decode_ptr);
+
+ return c;
+}
+
+void rfc2045_cdecode_start(struct rfc2045 *p,
+ rfc2045_decode_user_func_t u,
+ void *miscptr)
+{
+ enum mbfl_no_encoding from = mbfl_no_encoding_8bit;
+
+ if (p->content_transfer_encoding)
+ {
+ from = mbfl_name2no_encoding(p->content_transfer_encoding);
+ if (from == mbfl_no_encoding_invalid) {
+ zend_error(E_WARNING, "%s(): I don't know how to decode %s transfer encoding!",
+ get_active_function_name(),
+ p->content_transfer_encoding);
+ from = mbfl_no_encoding_8bit;
+ }
+ }
+
+ p->misc_decode_ptr=miscptr;
+ p->udecode_func=u;
+ p->workbuflen=0;
+
+ if (from == mbfl_no_encoding_8bit)
+ p->decode_filter = NULL;
+ else
+ p->decode_filter = mbfl_convert_filter_new(
+ from, mbfl_no_encoding_8bit,
+ op_func,
+ NULL,
+ p
+ );
+}
+
+int rfc2045_cdecode_end(struct rfc2045 *p)
+{
+ if (p->decode_filter)
+ {
+ mbfl_convert_filter_flush(p->decode_filter);
+ mbfl_convert_filter_delete(p->decode_filter);
+ p->decode_filter = NULL;
+ }
+ return 0;
+}
+
+int rfc2045_cdecode(struct rfc2045 *p, const char *s, size_t l)
+{
+ if (s && l)
+ {
+ int i;
+
+ if (p->decode_filter)
+ {
+ for (i=0; i<l; i++)
+ {
+ if (mbfl_convert_filter_feed(s[i], p->decode_filter) < 0)
+ return -1;
+ }
+ }
+ else
+ return ((*p->udecode_func)(s,l,p->misc_decode_ptr));
+
+ }
+ return (0);
+}