aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@src.gnome.org>2000-05-23 02:14:39 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2000-05-23 02:14:39 +0800
commitd88be436d908708bb62a95ee06fbf8a104c36e1d (patch)
tree83b03c790f595d4ebc4265cf3fceec2d8ee97648
parent36c4f96edf9defe046fb21d1afc8b5997f49c7d8 (diff)
downloadgsoc2013-evolution-d88be436d908708bb62a95ee06fbf8a104c36e1d.tar
gsoc2013-evolution-d88be436d908708bb62a95ee06fbf8a104c36e1d.tar.gz
gsoc2013-evolution-d88be436d908708bb62a95ee06fbf8a104c36e1d.tar.bz2
gsoc2013-evolution-d88be436d908708bb62a95ee06fbf8a104c36e1d.tar.lz
gsoc2013-evolution-d88be436d908708bb62a95ee06fbf8a104c36e1d.tar.xz
gsoc2013-evolution-d88be436d908708bb62a95ee06fbf8a104c36e1d.tar.zst
gsoc2013-evolution-d88be436d908708bb62a95ee06fbf8a104c36e1d.zip
added camel-mime-filter-smtp.[c,h] and made mods to camel-mime-filter-from.c
svn path=/trunk/; revision=3163
-rw-r--r--camel/ChangeLog11
-rw-r--r--camel/camel-mime-filter-from.c33
-rw-r--r--camel/camel-mime-filter-smtp.c286
-rw-r--r--camel/camel-mime-filter-smtp.h50
4 files changed, 364 insertions, 16 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index 504b95bf7a..b4c784ce3f 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,3 +1,14 @@
+2000-05-22 Jeff Stedfast <fejj@helixcode.com>
+
+ * camel-mime-filter-from.c: formatting changes and changed
+ comparisons to be case-insensitive - no guarentee that "From "
+ tag will be in that case, it could be "fRoM " for all we know
+ since the RFC doesn't specify that it MUST be in that particular
+ case format.
+
+ * camel-mime-filter-smtp.[c,h]: added to tree but not makefiles.
+ Code needs to be tested.
+
2000-05-19 NotZed <NotZed@HelixCode.com>
* camel-simple-data-wrapper.c (construct_from_stream): If we
diff --git a/camel/camel-mime-filter-from.c b/camel/camel-mime-filter-from.c
index 065b15e656..271a97505f 100644
--- a/camel/camel-mime-filter-from.c
+++ b/camel/camel-mime-filter-from.c
@@ -1,3 +1,4 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2000 Helix Code Inc.
*
@@ -85,7 +86,7 @@ filter(CamelMimeFilter *mf, char *in, size_t len, size_t prespace, char **out, s
int left;
int midline = f->midline;
int fromcount = 0;
- struct fromnode *head= NULL, *tail = (struct fromnode *)&head, *node;
+ struct fromnode *head = NULL, *tail = (struct fromnode *)&head, *node;
char *outptr;
inptr = in;
@@ -95,25 +96,25 @@ filter(CamelMimeFilter *mf, char *in, size_t len, size_t prespace, char **out, s
/* first, see if we need to escape any from's */
while (inptr<inend) {
- register int c=-1;
+ register int c = -1;
if (midline)
- while (inptr<inend && (c=*inptr++) != '\n')
+ while (inptr < inend && (c = *inptr++) != '\n')
;
- if (c=='\n' || !midline) {
+ if (c == '\n' || !midline) {
left = inend-inptr;
if (left > 0) {
midline = TRUE;
- if (left<5) {
- if (inptr[0]=='F') {
+ if (left < 5) {
+ if (inptr[0] == 'F' || inptr[0] == 'f') {
camel_mime_filter_backup(mf, inptr, left);
midline = FALSE;
inend = inptr;
break;
}
} else {
- if (!strncmp(inptr, "From ", 5)) {
+ if (!g_strncasecmp(inptr, "From ", 5)) {
fromcount++;
/* yes, we do alloc them on the stack ... at most we're going to get
len / 7 of them anyway */
@@ -122,7 +123,7 @@ filter(CamelMimeFilter *mf, char *in, size_t len, size_t prespace, char **out, s
node->next = NULL;
tail->next = node;
tail = node;
- inptr+=5;
+ inptr += 5;
}
}
} else {
@@ -140,17 +141,17 @@ filter(CamelMimeFilter *mf, char *in, size_t len, size_t prespace, char **out, s
inptr = in;
outptr = mf->outbuf;
while (node) {
- memcpy(outptr, inptr, node->pointer-inptr);
- outptr+=node->pointer-inptr;
- *outptr++='>';
+ memcpy(outptr, inptr, node->pointer - inptr);
+ outptr += node->pointer - inptr;
+ *outptr++ = '>';
inptr = node->pointer;
node = node->next;
}
- memcpy(outptr, inptr, inend-inptr);
- outptr += inend-inptr;
+ memcpy(outptr, inptr, inend - inptr);
+ outptr += inend - inptr;
*out = mf->outbuf;
- *outlen = outptr-mf->outbuf;
- *outprespace = mf->outbuf-mf->outreal;
+ *outlen = outptr - mf->outbuf;
+ *outprespace = mf->outbuf - mf->outreal;
d(printf("Filtered '%.*s'\n", *outlen, *out));
} else {
@@ -231,7 +232,7 @@ int main(int argc, char **argv)
printf("output = '%.*s'\n", len, buffer);
buffer = "";
len = 0;
- prespace =0;
+ prespace = 0;
camel_mime_filter_complete(f, buffer, len, prespace, &buffer, &len, &prespace);
printf("complete = '%.*s'\n", len, buffer);
diff --git a/camel/camel-mime-filter-smtp.c b/camel/camel-mime-filter-smtp.c
new file mode 100644
index 0000000000..1b7320a70f
--- /dev/null
+++ b/camel/camel-mime-filter-smtp.c
@@ -0,0 +1,286 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2000 Helix Code Inc.
+ *
+ * Authors: Jeffrey Stedfast <fejj@helixcode.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#include "camel-mime-filter-smtp.h"
+#include <string.h>
+
+#define d(x)
+
+struct _CamelMimeFilterSmtpPrivate {
+};
+
+#define _PRIVATE(o) (((CamelMimeFilterSmtp *)(o))->priv)
+
+static void camel_mime_filter_smtp_class_init (CamelMimeFilterSmtpClass *klass);
+static void camel_mime_filter_smtp_init (CamelMimeFilterSmtp *obj);
+static void camel_mime_filter_smtp_finalise (GtkObject *obj);
+
+static CamelMimeFilterClass *camel_mime_filter_smtp_parent;
+
+enum SIGNALS {
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+guint
+camel_mime_filter_smtp_get_type (void)
+{
+ static guint type = 0;
+
+ if (!type) {
+ GtkTypeInfo type_info = {
+ "CamelMimeFilterSmtp",
+ sizeof (CamelMimeFilterSmtp),
+ sizeof (CamelMimeFilterSmtpClass),
+ (GtkClassInitFunc) camel_mime_filter_smtp_class_init,
+ (GtkObjectInitFunc) camel_mime_filter_smtp_init,
+ (GtkArgSetFunc) NULL,
+ (GtkArgGetFunc) NULL
+ };
+
+ type = gtk_type_unique (camel_mime_filter_get_type (), &type_info);
+ }
+
+ return type;
+}
+
+typedef enum { FROM_NODE, DOT_NODE } node_t;
+
+struct smtpnode {
+ struct smtpnode *next;
+ node_t type;
+ char *pointer;
+};
+
+static void
+complete(CamelMimeFilter *mf, char *in, size_t len, size_t prespace, char **out, size_t *outlen, size_t *outprespace)
+{
+ *out = in;
+ *outlen = len;
+ *outprespace = prespace;
+}
+
+/* Yes, it is complicated ... */
+static void
+filter(CamelMimeFilter *mf, char *in, size_t len, size_t prespace, char **out, size_t *outlen, size_t *outprespace)
+{
+ CamelMimeFilterSmtp *f = (CamelMimeFilterSmtp *)mf;
+ register char *inptr, *inend;
+ int left;
+ int midline = f->midline;
+ int fromcount = 0;
+ struct smtpnode *head = NULL, *tail = (struct smtpnode *)&head, *node;
+ char *outptr;
+
+ inptr = in;
+ inend = inptr + len;
+
+ d(printf("Filtering '%.*s'\n", len, in));
+
+ /* first, see if we need to escape any from's */
+ while (inptr < inend) {
+ register int c = -1;
+
+ if (midline)
+ while (inptr < inend && (c = *inptr++) != '\n')
+ ;
+
+ if (c == '\n' || !midline) {
+ left = inend - inptr;
+ if (left > 0) {
+ midline = TRUE;
+ if (left < 5) {
+ /* MUST check for upper and lower case F, since our "From " has no case guarentee */
+ if (inptr[0] == 'F' || inptr == 'f' || inptr == '.') {
+ camel_mime_filter_backup(mf, inptr, left);
+ midline = FALSE;
+ inend = inptr;
+ break;
+ }
+ } else {
+ if (!g_strncasecmp(inptr, "From ", 5)) {
+ fromcount++;
+ /* yes, we do alloc them on the stack ... at most we're going to get
+ len / 7 of them anyway */
+ node = alloca(sizeof(*node));
+ node->type = FROM_NODE;
+ node->pointer = inptr;
+ node->next = NULL;
+ tail->next = node;
+ tail = node;
+ inptr += 5;
+ } else {
+ if (!strncmp(inptr, ".\n", 2) || !strncmp(inptr, ".\r\n", 3)) {
+ fromcount++;
+ node = alloca(sizeof(*node));
+ node->type = DOT_NODE;
+ node->pointer = inptr;
+ node->next = NULL;
+ tail->next = node;
+ tail = node;
+ if (inptr[1] == '\n')
+ inptr += 2;
+ else
+ inptr += 3;
+ }
+ }
+ }
+ } else {
+ /* \n is at end of line, check next buffer */
+ midline = FALSE;
+ }
+ }
+ }
+
+ f->midline = midline;
+
+ if (fromcount > 0) {
+ camel_mime_filter_set_size(mf, len + fromcount, FALSE);
+ node = head;
+ inptr = in;
+ outptr = mf->outbuf;
+ while (node) {
+ memcpy(outptr, inptr, node->pointer - inptr);
+ outptr += node->pointer - inptr;
+ if (node->type == FROM_NODE)
+ *outptr++ = '>';
+ else
+ *outptr++ = '.';
+ inptr = node->pointer;
+ node = node->next;
+ }
+ memcpy(outptr, inptr, inend - inptr);
+ outptr += inend - inptr;
+ *out = mf->outbuf;
+ *outlen = outptr - mf->outbuf;
+ *outprespace = mf->outbuf - mf->outreal;
+
+ d(printf("Filtered '%.*s'\n", *outlen, *out));
+ } else {
+ *out = in;
+ *outlen = inend - in;
+ *outprespace = prespace;
+
+ d(printf("Filtered '%.*s'\n", *outlen, *out));
+ }
+}
+
+static void
+camel_mime_filter_smtp_class_init (CamelMimeFilterSmtpClass *klass)
+{
+ GtkObjectClass *object_class = (GtkObjectClass *) klass;
+ CamelMimeFilterClass *filter_class = (CamelMimeFilterClass *) klass;
+
+ camel_mime_filter_smtp_parent = gtk_type_class (camel_mime_filter_get_type ());
+
+ object_class->finalize = camel_mime_filter_smtp_finalise;
+
+ filter_class->filter = filter;
+ filter_class->complete = complete;
+
+ gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL);
+}
+
+static void
+camel_mime_filter_smtp_init (CamelMimeFilterSmtp *obj)
+{
+ struct _CamelMimeFilterSmtpPrivate *p;
+
+ p = _PRIVATE(obj) = g_malloc0(sizeof(*p));
+ obj->midline = FALSE;
+}
+
+static void
+camel_mime_filter_smtp_finalise (GtkObject *obj)
+{
+ ((GtkObjectClass *)(camel_mime_filter_smtp_parent))->finalize((GtkObject *)obj);
+}
+
+/**
+ * camel_mime_filter_smtp_new:
+ *
+ * Create a new CamelMimeFilterSmtp object.
+ *
+ * Return value: A new CamelMimeFilterSmtp widget.
+ **/
+CamelMimeFilterSmtp *
+camel_mime_filter_smtp_new (void)
+{
+ CamelMimeFilterSmtp *new = CAMEL_MIME_FILTER_SMTP (gtk_type_new (camel_mime_filter_smtp_get_type ()));
+ return new;
+}
+
+#if 0
+
+#include <stdio.h>
+
+int main(int argc, char **argv)
+{
+ CamelMimeFilterSmtp *f;
+ char *buffer;
+ int len, prespace;
+
+ gtk_init(&argc, &argv);
+
+
+ f = camel_mime_filter_smtp_new();
+
+ buffer = "This is a test\nFrom Someone\nTo someone. From Someone else, From\n From blah\nFromblah\nBye! \nFrom \n.\n.\r\nprevious 2 lines had .'s\nfrom should also be escaped\n";
+ len = strlen(buffer);
+ prespace = 0;
+
+ printf("input = '%.*s'\n", len, buffer);
+ camel_mime_filter_filter(f, buffer, len, prespace, &buffer, &len, &prespace);
+ printf("output = '%.*s'\n", len, buffer);
+ buffer = "";
+ len = 0;
+ prespace = 0;
+ camel_mime_filter_complete(f, buffer, len, prespace, &buffer, &len, &prespace);
+ printf("complete = '%.*s'\n", len, buffer);
+
+
+ return 0;
+}
+
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/camel/camel-mime-filter-smtp.h b/camel/camel-mime-filter-smtp.h
new file mode 100644
index 0000000000..6bfa20e9c4
--- /dev/null
+++ b/camel/camel-mime-filter-smtp.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2000 Helix Code Inc.
+ *
+ * Authors: Jeffrey Stedfast <fejj@helixcode.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#ifndef _CAMEL_MIME_FILTER_SMTP_H
+#define _CAMEL_MIME_FILTER_SMTP_H
+
+#include <gtk/gtk.h>
+#include <camel/camel-mime-filter.h>
+
+#define CAMEL_MIME_FILTER_SMTP(obj) GTK_CHECK_CAST (obj, camel_mime_filter_smtp_get_type (), CamelMimeFilterSmtp)
+#define CAMEL_MIME_FILTER_SMTP_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, camel_mime_filter_smtp_get_type (), CamelMimeFilterSmtpClass)
+#define IS_CAMEL_MIME_FILTER_SMTP(obj) GTK_CHECK_TYPE (obj, camel_mime_filter_smtp_get_type ())
+
+typedef struct _CamelMimeFilterSmtp CamelMimeFilterSmtp;
+typedef struct _CamelMimeFilterSmtpClass CamelMimeFilterSmtpClass;
+
+struct _CamelMimeFilterSmtp {
+ CamelMimeFilter parent;
+
+ struct _CamelMimeFilterSmtpPrivate *priv;
+
+ int midline; /* are we between lines? */
+};
+
+struct _CamelMimeFilterSmtpClass {
+ CamelMimeFilterClass parent_class;
+};
+
+guint camel_mime_filter_smtp_get_type (void);
+CamelMimeFilterFrom *camel_mime_filter_smtp_new (void);
+
+#endif /* ! _CAMEL_MIME_FILTER_SMTP_H */