1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; fill-column: 160 -*-
4 * Michael Zucchi <notzed@ximian.com>
6 * Copyright 1999, 2000 Ximian, Inc. (www.ximian.com)
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU Lesser General Public
10 * License as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
34 #include "camel-stream-mem.h"
36 #include "camel-imapp-exception.h"
37 #include "camel-imapp-stream.h"
42 static CamelObjectClass *parent_class = NULL;
44 /* Returns the class for a CamelStream */
45 #define CS_CLASS(so) CAMEL_IMAPP_FETCH_STREAM_CLASS(CAMEL_OBJECT_GET_CLASS(so))
48 stream_read(CamelStream *stream, char *buffer, size_t n)
50 CamelIMAPPFetchStream *is = (CamelIMAPPFetchStream *)stream;
53 /* make sure we have all the data read in */
54 while (camel_imapp_engine_iterate(is->engine, is->command)>0)
57 if (is->literal == 0 || n == 0)
60 max = is->end - is->ptr;
62 max = MIN(max, is->literal);
64 memcpy(buffer, is->ptr, max);
67 max = MIN(is->literal, n);
68 max = camel_stream_read(is->source, buffer, max);
79 stream_write(CamelStream *stream, const char *buffer, size_t n)
81 CamelIMAPPFetchStream *is = (CamelIMAPPFetchStream *)stream;
83 return camel_stream_write(is->source, buffer, n);
87 stream_close(CamelStream *stream)
94 stream_flush(CamelStream *stream)
101 stream_eos(CamelStream *stream)
103 CamelIMAPPFetchStream *is = (CamelIMAPPFetchStream *)stream;
105 return is->literal == 0;
109 stream_reset(CamelStream *stream)
111 /* nop? reset literal mode? */
116 camel_imapp_fetch_stream_class_init (CamelStreamClass *camel_imapp_fetch_stream_class)
118 CamelStreamClass *camel_stream_class = (CamelStreamClass *)camel_imapp_fetch_stream_class;
120 parent_class = camel_type_get_global_classfuncs( CAMEL_OBJECT_TYPE );
122 /* virtual method definition */
123 camel_stream_class->read = stream_read;
124 camel_stream_class->write = stream_write;
125 camel_stream_class->close = stream_close;
126 camel_stream_class->flush = stream_flush;
127 camel_stream_class->eos = stream_eos;
128 camel_stream_class->reset = stream_reset;
132 camel_imapp_fetch_stream_init(CamelIMAPPFetchStream *is, CamelIMAPPFetchStreamClass *isclass)
138 camel_imapp_fetch_stream_finalise(CamelIMAPPFetchStream *is)
141 camel_object_unref(is->engine);
145 camel_imapp_fetch_stream_get_type (void)
147 static CamelType camel_imapp_fetch_stream_type = CAMEL_INVALID_TYPE;
149 if (camel_imapp_fetch_stream_type == CAMEL_INVALID_TYPE) {
151 camel_imapp_fetch_stream_type = camel_type_register( camel_stream_get_type(),
152 "CamelIMAPPFetchStream",
153 sizeof( CamelIMAPPFetchStream ),
154 sizeof( CamelIMAPPFetchStreamClass ),
155 (CamelObjectClassInitFunc) camel_imapp_fetch_stream_class_init,
157 (CamelObjectInitFunc) camel_imapp_fetch_stream_init,
158 (CamelObjectFinalizeFunc) camel_imapp_fetch_stream_finalise );
161 return camel_imapp_fetch_stream_type;
165 * camel_imapp_fetch_stream_new:
167 * Return value: the stream
170 camel_imapp_fetch_stream_new(CamelIMAPPEngine *ie, const char *uid, const char *body)
172 CamelIMAPPFetchStream *is;
174 is = (CamelIMAPPFetchStream *)camel_object_new(camel_imapp_fetch_stream_get_type ());
176 camel_object_ref(ie);
178 is->command = camel_imapp_engine_command_new(ie, "FETCH", NULL, "FETCH %t (BODY[%t]<0.4096>", uid, body);
179 camel_imapp_engine_command_queue(ie, command);
181 return (CamelStream *)is;