$Log$
+ Revision 573.20 2000/11/06 05:10:01 ajc
+ * Changed the mime_parser() API (again) to allow "don't decode" mode
+
Revision 573.19 2000/10/29 18:11:07 ajc
* Start numbering top-level MIME parts as 1, 2... not 1.1, 1.2...
Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
* Initial CVS import
-
/*
- * FIXME this is TOTALLY BROKEN!!!
+ * Load a specific part of a message into the temp file to be output to a
+ * client. FIXME we can handle parts like "2" and "2.1" but we still have
+ * to handle parts like "2.MIME" and "2.HEADER" (the latter maybe not ...
+ * Mark Crispy's server doesn't seem to)
+ *
+ * Note: mime_parser() was called with dont_decode set to 1, so we have the
+ * luxury of simply spewing without having to re-encode.
*/
-void imap_fetch_part(char *name, char *filename, char *partnum, char *disp,
- void *content, char *cbtype, size_t length,
+void imap_load_part(char *name, char *filename, char *partnum, char *disp,
+ void *content, char *cbtype, size_t length, char *encoding,
void *cbuserdata)
{
struct imap_fetch_part *imfp;
imfp = (struct imap_fetch_part *)cbuserdata;
if (!strcasecmp(partnum, imfp->desired_section)) {
- cprintf("part=%s|%s|%s|%s|%s|%d\r\n",
- name, filename, partnum, disp, cbtype, length, NULL);
+ fwrite(content, length, 1, imfp->output_fp);
}
+
}
/*
* Anything else must be a part specifier.
+ * (Note value of 1 passed as 'dont_decode' so client gets it encoded)
*/
else {
safestrncpy(imfp.desired_section, section,
imfp.output_fp = tmp;
mime_parser(msg->cm_fields['M'], NULL,
- *imap_fetch_part,
- (void *)&imfp);
+ *imap_load_part,
+ (void *)&imfp,
+ 1);
}
void *cbcontent,
char *cbtype,
size_t cblength,
+ char *cbencoding,
void *cbuserdata),
- void *userdata
+ void *userdata,
+ int dont_decode
)
{
strcpy(encoding, "");
/* If this part is not encoded, send as-is */
- if (strlen(encoding) == 0) {
+ if ( (strlen(encoding) == 0) || (dont_decode)) {
CallBack(name, filename, partnum, disposition, part_start,
- content_type, length, userdata);
+ content_type, length, encoding, userdata);
return;
}
if ((strcasecmp(encoding, "base64"))
if (bytes_recv > 0)
CallBack(name, filename, partnum, disposition, decoded,
- content_type, bytes_recv, userdata);
+ content_type, bytes_recv, "binary", userdata);
phree(decoded);
}
void *cbcontent,
char *cbtype,
size_t cblength,
+ char *cbencoding,
void *cbuserdata),
- void *userdata
+ void *userdata,
+ int dont_decode
)
{
if (is_multipart) {
/* Tell the client about this message's multipartedness */
- CallBack("", "", partnum, "", NULL, content_type, 0, userdata);
+ CallBack("", "", partnum, "", NULL, content_type, 0,
+ encoding, userdata);
/* Figure out where the boundaries are */
sprintf(startary, "--%s", boundary);
}
the_mime_parser(nested_partnum,
part_start, part_end,
- CallBack, userdata);
+ CallBack, userdata,
+ dont_decode);
}
part_start = ptr;
}
mime_decode(partnum,
part_start, length,
content_type, encoding, disposition,
- name, filename, CallBack, userdata);
+ name, filename, CallBack, userdata, dont_decode);
}
void *cbcontent,
char *cbtype,
size_t cblength,
+ char *cbencoding,
void *cbuserdata),
- void *userdata
+ void *userdata,
+ int dont_decode
)
{
lprintf(9, "mime_parser() called\n");
- the_mime_parser("", content_start, content_end, CallBack, userdata);
+ the_mime_parser("", content_start, content_end, CallBack,
+ userdata, dont_decode);
}
void *cbcontent,
char *cbtype,
size_t cblength,
+ char *cbencoding,
void *cbuserdata),
- void *userdata
+ void *userdata,
+ int dont_decode
);
* Callback function for mime parser that simply lists the part
*/
void list_this_part(char *name, char *filename, char *partnum, char *disp,
- void *content, char *cbtype, size_t length,
+ void *content, char *cbtype, size_t length, char *encoding,
void *cbuserdata)
{
* Callback function for mime parser that opens a section for downloading
*/
void mime_download(char *name, char *filename, char *partnum, char *disp,
- void *content, char *cbtype, size_t length,
+ void *content, char *cbtype, size_t length, char *encoding,
void *cbuserdata)
{
* Callback function for mime parser that wants to display text
*/
void fixed_output(char *name, char *filename, char *partnum, char *disp,
- void *content, char *cbtype, size_t length,
+ void *content, char *cbtype, size_t length, char *encoding,
void *cbuserdata)
{
char *ptr;
} else {
/* Parse the message text component */
mptr = TheMessage->cm_fields['M'];
- mime_parser(mptr, NULL, *mime_download, NULL);
+ mime_parser(mptr, NULL, *mime_download, NULL, 0);
/* If there's no file open by this time, the requested
* section wasn't found, so print an error
*/
/* Tell the client about the MIME parts in this message */
if (TheMessage->cm_format_type == FMT_RFC822) {
if (mode == MT_CITADEL) {
- mime_parser(mptr, NULL, *list_this_part, NULL);
+ mime_parser(mptr, NULL, *list_this_part, NULL, 0);
}
else if (mode == MT_MIME) { /* list parts only */
- mime_parser(mptr, NULL, *list_this_part, NULL);
+ mime_parser(mptr, NULL, *list_this_part, NULL, 0);
if (do_proto) cprintf("000\n");
CtdlFreeMessage(TheMessage);
return(om_ok);
if (TheMessage->cm_format_type == FMT_RFC822) {
CtdlAllocUserData(SYM_MA_INFO, sizeof(struct ma_info));
memset(ma, 0, sizeof(struct ma_info));
- mime_parser(mptr, NULL, *fixed_output, NULL);
+ mime_parser(mptr, NULL, *fixed_output, NULL, 0);
}
/* now we're done */