diff options
Diffstat (limited to 'camel')
-rw-r--r-- | camel/ChangeLog | 15 | ||||
-rw-r--r-- | camel/Makefile.am | 1 | ||||
-rw-r--r-- | camel/camel-mime-filter-crlf.c | 30 | ||||
-rw-r--r-- | camel/camel-mime-filter-crlf.h | 11 | ||||
-rw-r--r-- | camel/camel-mime-filter-smtp.c | 284 | ||||
-rw-r--r-- | camel/camel-mime-filter-smtp.h | 50 | ||||
-rw-r--r-- | camel/camel-mime-part.c | 3 | ||||
-rw-r--r-- | camel/providers/imap/camel-imap-folder.c | 24 | ||||
-rw-r--r-- | camel/providers/smtp/camel-smtp-transport.c | 16 |
9 files changed, 82 insertions, 352 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog index c7c7f66629..2bf9726a94 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,3 +1,18 @@ +2000-06-12 Jeffrey Stedfast <fejj@helixcode.com> + + * camel-mime-filter-smtp.c: Deprecated. + + * providers/smtp/camel-smtp-transport.c (smtp_data): Updated to use + camel-mime-filter-crlf with my 'dot' extension in place of + camel-mime-filter-smtp + + * camel-mime-part.c (write_to_stream): Updated to reflect changes + made to camel-mime-filter-crlf.c + + * camel-mime-filter-crlf.c (filter): Modified to be able to + encode/decode dots ("\n.\n"<->"\n..\n"). Also fixed the decoder + so that it should no longer get caught in an infinite loop. + 2000-06-12 Dan Winship <danw@helixcode.com> * providers/*/Makefile.am: don't pass a second (incorrect) -rpath diff --git a/camel/Makefile.am b/camel/Makefile.am index 8505bc1819..b56dcbf30e 100644 --- a/camel/Makefile.am +++ b/camel/Makefile.am @@ -53,7 +53,6 @@ libcamel_la_SOURCES = \ camel-mime-filter-charset.c \ camel-mime-filter-index.c \ camel-mime-filter-from.c \ - camel-mime-filter-smtp.c \ camel-mime-filter-crlf.c \ camel-stream-filter.c \ camel-address.c \ diff --git a/camel/camel-mime-filter-crlf.c b/camel/camel-mime-filter-crlf.c index d39d00887f..63ebfca62b 100644 --- a/camel/camel-mime-filter-crlf.c +++ b/camel/camel-mime-filter-crlf.c @@ -1,7 +1,9 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2000 Helix Code, Inc. * * Authors: Dan Winship <danw@helixcode.com> + * Jeffrey Stedfast <fejj@helixcode.com> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public License @@ -68,8 +70,11 @@ filter (CamelMimeFilter *f, char *in, size_t len, size_t prespace, char **out, size_t *outlen, size_t *outprespace) { CamelMimeFilterCRLF *crlf = (CamelMimeFilterCRLF *)f; + gboolean do_dots; char *p, *q; + do_dots = crlf->mode == CAMEL_MIME_FILTER_CRLF_MODE_CRLF_DOTS; + if (crlf->direction == CAMEL_MIME_FILTER_CRLF_ENCODE) { camel_mime_filter_set_size (f, 2 * len, FALSE); @@ -78,6 +83,9 @@ filter (CamelMimeFilter *f, char *in, size_t len, size_t prespace, while (p < in + len) { if (*p == '\n') *q++ = '\r'; + else + if (do_dots && *(p - 1) == '\n' && *p == '.' && *(p + 1) != '.') + *q++ = '.'; *q++ = *p++; } } else { @@ -86,9 +94,10 @@ filter (CamelMimeFilter *f, char *in, size_t len, size_t prespace, p = in; q = f->outbuf; while (p < in + len) { - if (*p == '\r') + if (*p == '\r') { crlf->saw_cr = TRUE; - else { + p++; + } else { if (crlf->saw_cr) { if (*p != '\n') *q++ = '\r'; @@ -96,6 +105,20 @@ filter (CamelMimeFilter *f, char *in, size_t len, size_t prespace, } *q++ = *p++; } + + if (do_dots) { + if (*p == '.' && *(p - 1) == '\n') { + crlf->saw_dot = TRUE; + p++; + } else { + if (crlf->saw_dot) { + if (*p == '.') + p++; + crlf->saw_dot = FALSE; + } + *q++ = *p++; + } + } } } @@ -121,11 +144,12 @@ reset (CamelMimeFilter *f) } CamelMimeFilter * -camel_mime_filter_crlf_new (CamelMimeFilterCRLFDirection direction) +camel_mime_filter_crlf_new (CamelMimeFilterCRLFDirection direction, CamelMimeFilterCRLFMode mode) { CamelMimeFilterCRLF *crlf = gtk_type_new (CAMEL_MIME_FILTER_CRLF_TYPE); crlf->direction = direction; + crlf->mode = mode; crlf->saw_cr = FALSE; return (CamelMimeFilter *)crlf; diff --git a/camel/camel-mime-filter-crlf.h b/camel/camel-mime-filter-crlf.h index 57b6869446..27f78030e3 100644 --- a/camel/camel-mime-filter-crlf.h +++ b/camel/camel-mime-filter-crlf.h @@ -1,7 +1,9 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2000 Helix Code Inc. * * Authors: Dan Winship <danw@helixcode.com> + * Jeffrey Stedfast <fejj@helixcode.com> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public License @@ -35,11 +37,18 @@ typedef enum { CAMEL_MIME_FILTER_CRLF_DECODE } CamelMimeFilterCRLFDirection; +typedef enum { + CAMEL_MIME_FILTER_CRLF_MODE_CRLF_DOTS, + CAMEL_MIME_FILTER_CRLF_MODE_CRLF_ONLY, +} CamelMimeFilterCRLFMode; + struct _CamelMimeFilterCRLF { CamelMimeFilter parent; CamelMimeFilterCRLFDirection direction; + CamelMimeFilterCRLFMode mode; gboolean saw_cr; + gboolean saw_dot; }; struct _CamelMimeFilterCRLFClass { @@ -48,6 +57,6 @@ struct _CamelMimeFilterCRLFClass { GtkType camel_mime_filter_crlf_get_type (void); -CamelMimeFilter *camel_mime_filter_crlf_new (CamelMimeFilterCRLFDirection direction); +CamelMimeFilter *camel_mime_filter_crlf_new (CamelMimeFilterCRLFDirection direction, CamelMimeFilterCRLFMode mode); #endif /* ! _CAMEL_MIME_FILTER_CRLF_H */ diff --git a/camel/camel-mime-filter-smtp.c b/camel/camel-mime-filter-smtp.c deleted file mode 100644 index f02a951306..0000000000 --- a/camel/camel-mime-filter-smtp.c +++ /dev/null @@ -1,284 +0,0 @@ -/* -*- 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> - -#include <stdio.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 { EOLN_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 gchar *inptr, *inend; - guint linecount = 0; - guint dotcount = 0; - gint left; - gint midline = f->midline; - struct smtpnode *head = NULL, *tail = (struct smtpnode *)&head, *node; - gchar *outptr = NULL; - - inptr = in; - inend = inptr + len; - - while (inptr < inend) { - register gint c = -1; - - if (midline) - while (inptr < inend && (c = *inptr++) != '\n') - ; - - if (c == '\n' || !midline) { - /* if there isn't already a carriage-return before the line-feed, count it */ - if (c == '\n') { - linecount++; - node = alloca (sizeof (*node)); - node->type = EOLN_NODE; - node->pointer = inptr - 1; - node->next = NULL; - tail->next = node; - tail = node; - } - - left = inend - inptr; - if (left > 0) { - midline = TRUE; - if (left < 2) { - if (*inptr == '.') { - camel_mime_filter_backup (mf, inptr, left); - midline = FALSE; - inend = inptr; - break; - } - } else { - /* we only need to escape dots if they start the line */ - if (*inptr == '.' && *(inptr+1) != '.') { - midline = TRUE; - dotcount++; - node = alloca (sizeof (*node)); - node->type = DOT_NODE; - node->pointer = inptr; - node->next = NULL; - tail->next = node; - tail = node; - inptr++; - } - } - } else { - /* \n is at end of line, check next buffer */ - midline = FALSE; - } - } - } - - f->midline = midline; - - if (dotcount > 0 || linecount > 0) { - camel_mime_filter_set_size (mf, len + dotcount + linecount, FALSE); - node = head; - inptr = in; - outptr = mf->outbuf; - while (node) { - g_assert(node->pointer >= inptr); - memcpy (outptr, inptr, node->pointer - inptr); - outptr += node->pointer - inptr; - if (node->type == EOLN_NODE) { - *outptr++ = '\r'; - } else if (node->type == DOT_NODE) { - *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 [%d] '%.*s'\n", *outlen, *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; -} - -#ifdef TEST_PROGRAM - -#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 deleted file mode 100644 index 545b339431..0000000000 --- a/camel/camel-mime-filter-smtp.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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); -CamelMimeFilterSmtp *camel_mime_filter_smtp_new (void); - -#endif /* ! _CAMEL_MIME_FILTER_SMTP_H */ diff --git a/camel/camel-mime-part.c b/camel/camel-mime-part.c index d19cace9c0..14b8106314 100644 --- a/camel/camel-mime-part.c +++ b/camel/camel-mime-part.c @@ -530,7 +530,8 @@ write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) if (filter) { filter_stream = camel_stream_filter_new_with_stream(stream); if (!strcasecmp(mp->content_type->type, "text")) { - CamelMimeFilter *crlf = camel_mime_filter_crlf_new(CAMEL_MIME_FILTER_CRLF_ENCODE); + CamelMimeFilter *crlf = camel_mime_filter_crlf_new(CAMEL_MIME_FILTER_CRLF_ENCODE, + CAMEL_MIME_FILTER_CRLF_MODE_CRLF_ONLY); camel_stream_filter_add(filter_stream, crlf); gtk_object_unref((GtkObject *)crlf); } diff --git a/camel/providers/imap/camel-imap-folder.c b/camel/providers/imap/camel-imap-folder.c index 722b6bbd9e..4e6e184c48 100644 --- a/camel/providers/imap/camel-imap-folder.c +++ b/camel/providers/imap/camel-imap-folder.c @@ -436,7 +436,7 @@ imap_append_message (CamelFolder *folder, CamelMimeMessage *message, CamelExcept return; } - mem->buffer = g_byte_array_append(mem->buffer, g_strdup("\n"), 2); + mem->buffer = g_byte_array_append(mem->buffer, g_strdup("\r\n"), 3); status = camel_imap_command(CAMEL_IMAP_STORE (folder->parent_store), folder, &result, "APPEND %s (\\Seen) {%d}\r\n%s", @@ -605,13 +605,29 @@ message_changed (CamelMimeMessage *m, int type, CamelImapFolder *mf) static CamelMimeMessage * imap_get_message_by_uid (CamelFolder *folder, const gchar *uid, CamelException *ex) { - CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (folder); - CamelImapStore *store = CAMEL_IMAP_STORE (folder->parent_store); CamelImapStream *imap_stream; CamelMimeMessage *message; - gchar *cmdid, *cmdbuf; + CamelMimePart *part; + CamelDataWrapper *cdw; + gchar *cmdbuf; + + /* TODO: fetch the correct part, get rid of the hard-coded stuff */ + cmdbuf = g_strdup_printf("UID FETCH %s BODY[TEXT]", uid); + imap_stream = camel_imap_stream_new(folder, cmdbuf); + g_free(cmdbuf); + message = camel_mime_message_new(); + + cdw = camel_data_wrapper_new(); + camel_data_wrapper_construct_from_stream(cdw, imap_stream); + gtk_object_unref(GTK_OBJECT (imap_stream)); + camel_data_wrapper_set_mime_type (cdw, "text/plain"); + + camel_medium_set_content_object (CAMEL_MEDIUM (message), CAMEL_DATA_WRAPPER (cdw)); + gtk_object_unref (GTK_OBJECT (cdw)); + + return message; } #if 0 diff --git a/camel/providers/smtp/camel-smtp-transport.c b/camel/providers/smtp/camel-smtp-transport.c index 74ab08dc99..ed5f0416b3 100644 --- a/camel/providers/smtp/camel-smtp-transport.c +++ b/camel/providers/smtp/camel-smtp-transport.c @@ -37,7 +37,7 @@ #include <unistd.h> #undef MIN #undef MAX -#include "camel-mime-filter-smtp.h" +#include "camel-mime-filter-crlf.h" #include "camel-stream-filter.h" #include "camel-smtp-transport.h" #include "camel-mime-message.h" @@ -623,7 +623,7 @@ smtp_data (CamelSmtpTransport *transport, CamelMedium *message, CamelException * /* now we can actually send what's important :p */ gchar *cmdbuf, *respbuf = NULL; CamelStreamFilter *filtered_stream; - CamelMimeFilterSmtp *mimefilter; + CamelMimeFilter *mimefilter; gint id; /* enclose address in <>'s since some SMTP daemons *require* that */ @@ -631,7 +631,7 @@ smtp_data (CamelSmtpTransport *transport, CamelMedium *message, CamelException * fprintf (stderr, "sending : %s", cmdbuf); - if ( camel_stream_write (transport->ostream, cmdbuf, strlen (cmdbuf)) == -1) { + if (camel_stream_write (transport->ostream, cmdbuf, strlen (cmdbuf)) == -1) { g_free (cmdbuf); camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, "DATA request timed out: " @@ -645,7 +645,7 @@ smtp_data (CamelSmtpTransport *transport, CamelMedium *message, CamelException * fprintf (stderr, "received: %s\n", respbuf ? respbuf : "(null)"); - if ( !respbuf || strncmp (respbuf, "354", 3) ) { + if (!respbuf || strncmp (respbuf, "354", 3) ) { /* we should have gotten instructions on how to use the DATA command: * 354 Enter mail, end with "." on a line by itself */ @@ -658,7 +658,7 @@ smtp_data (CamelSmtpTransport *transport, CamelMedium *message, CamelException * } /* setup stream filtering */ - mimefilter = camel_mime_filter_smtp_new (); + mimefilter = camel_mime_filter_crlf_new (CAMEL_MIME_FILTER_CRLF_ENCODE, CAMEL_MIME_FILTER_CRLF_MODE_CRLF_DOTS); filtered_stream = camel_stream_filter_new_with_stream (transport->ostream); id = camel_stream_filter_add (filtered_stream, CAMEL_MIME_FILTER (mimefilter)); @@ -693,14 +693,14 @@ smtp_data (CamelSmtpTransport *transport, CamelMedium *message, CamelException * fprintf (stderr, "received: %s\n", respbuf ? respbuf : "(null)"); - if ( !respbuf || strncmp (respbuf, "250", 3) ) { + if (!respbuf || strncmp (respbuf, "250", 3)) { camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, "DATA response error: message termination: " "%s: mail not sent", g_strerror (errno)); return FALSE; } - } while ( *(respbuf+3) == '-' ); /* if we got "250-" then loop again */ + } while (*(respbuf+3) == '-'); /* if we got "250-" then loop again */ g_free (respbuf); return TRUE; @@ -733,7 +733,7 @@ smtp_rset (CamelSmtpTransport *transport, CamelException *ex) fprintf (stderr, "received: %s\n", respbuf ? respbuf : "(null)"); - if ( !respbuf || strncmp (respbuf, "250", 3) ) { + if (!respbuf || strncmp (respbuf, "250", 3)) { camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, "RSET response error: " "%s", |