* just one mime struct should fit it all.
pthread_key_t MyConKey; /**< TSD key for MySession() */
-/*
- * free the memory used for viewing atachments
- */
-void free_attachment(void *vattach) {
- wc_attachment *att = (wc_attachment*) vattach;
- FreeStrBuf(&att->content_type);
- FreeStrBuf(&att->filename);
- free(att->data);
- free(att);
-}
-
void DestroySession(struct wcsession **sessions_to_kill)
{
char *attachments = NULL;
char *ptr = NULL;
int num_attachments = 0;
- wc_attachment *att;
+ //wc_attachment *att;
char m_subject[1024];
char from[256];
char node[256];
lprintf(9, "fwd dispose : %s\n", mime_disposition);
lprintf(9, "fwd length : %d\n", mime_length);
- if ( (!strcasecmp(mime_disposition, "inline"))
- || (!strcasecmp(mime_disposition, "attachment")) ) {
+/// if ( (!strcasecmp(mime_disposition, "inline"))
+/// || (!strcasecmp(mime_disposition, "attachment")) ) {
- int n;
- char N[64];
- /* Create an attachment struct from this mime part... */
- att = malloc(sizeof(wc_attachment));
- memset(att, 0, sizeof(wc_attachment));
- att->length = mime_length;
- att->content_type = NewStrBufPlain(mime_content_type, -1);
- att->filename = NewStrBufPlain(mime_filename, -1);
- att->data = load_mimepart(msgnum, mime_partnum);
-
- if (WCC->attachments == NULL)
- WCC->attachments = NewHash(1, NULL);
- /* And add it to the list. */
- n = snprintf(N, sizeof N, "%d", GetCount(WCC->attachments) + 1);
- Put(WCC->attachments, N, n, att, free_attachment);
- }
+///// int n;
+///// char N[64];
+///// /* Create an attachment struct from this mime part... */
+///// att = malloc(sizeof(wc_attachment));
+///// memset(att, 0, sizeof(wc_attachment));
+///// att->length = mime_length;
+///// att->content_type = NewStrBufPlain(mime_content_type, -1);
+///// att->filename = NewStrBufPlain(mime_filename, -1);
+///// att->data = load_mimepart(msgnum, mime_partnum);
+/////
+///// if (WCC->attachments == NULL)
+///// WCC->attachments = NewHash(1, NULL);
+///// /* And add it to the list. */
+///// n = snprintf(N, sizeof N, "%d", GetCount(WCC->attachments) + 1);
+///// Put(WCC->attachments, N, n, att, free_attachment);
+///// }
}
}
char alt_boundary[SIZ];
int is_multipart = 0;
static int seq = 0;
- wc_attachment *att;
+ wc_mime_attachment *att;
char *encoded;
size_t encoded_length;
size_t encoded_strlen;
/* Add in the attachments */
it = GetNewHashPos(WCC->attachments, 0);
while (GetNextHashPos(WCC->attachments, it, &len, &Key, &vAtt)) {
- att = (wc_attachment*)vAtt;
+ att = (wc_mime_attachment *)vAtt;
encoded_length = ((att->length * 150) / 100);
encoded = malloc(encoded_length);
if (encoded == NULL) break;
- encoded_strlen = CtdlEncodeBase64(encoded, att->data, att->length, 1);
+ encoded_strlen = CtdlEncodeBase64(encoded, ChrPtr(att->Data), StrLength(att->Data), 1);
serv_printf("--%s", top_boundary);
- serv_printf("Content-type: %s", ChrPtr(att->content_type));
- serv_printf("Content-disposition: attachment; filename=\"%s\"", ChrPtr(att->filename));
+ serv_printf("Content-type: %s", ChrPtr(att->ContentType));
+ serv_printf("Content-disposition: attachment; filename=\"%s\"", ChrPtr(att->FileName));
serv_puts("Content-transfer-encoding: base64");
serv_puts("");
serv_write(encoded, encoded_strlen);
char buf[1024];
StrBuf *encoded_subject = NULL;
static long dont_post = (-1L);
- wc_attachment *att;
+ wc_mime_attachment *att;
int is_anonymous = 0;
const StrBuf *display_name = NULL;
struct wcsession *WCC = WC;
lprintf(9, "%s:%d: we are uploading %d bytes\n", __FILE__, __LINE__, WCC->upload_length);
/** There's an attachment. Save it to this struct... */
- att = malloc(sizeof(wc_attachment));
- memset(att, 0, sizeof(wc_attachment));
+ att = malloc(sizeof(wc_mime_attachment));
+ memset(att, 0, sizeof(wc_mime_attachment ));
att->length = WCC->upload_length;
- att->content_type = NewStrBufPlain(WCC->upload_content_type, -1);
- att->filename = NewStrBufPlain(WCC->upload_filename, -1);
+ att->ContentType = NewStrBufPlain(WCC->upload_content_type, -1);
+ att->FileName = NewStrBufPlain(WCC->upload_filename, -1);
if (WCC->attachments == NULL)
WCC->attachments = NewHash(1, NULL);
/* And add it to the list. */
n = snprintf(N, sizeof N, "%d", GetCount(WCC->attachments) + 1);
- Put(WCC->attachments, N, n, att, free_attachment);
+ Put(WCC->attachments, N, n, att, DestroyMime);
/**
* Mozilla sends a simple filename, which is what we want,
* but Satan's Browser sends an entire pathname. Reduce
* the path to just a filename if we need to.
*/
- pch = strrchr(ChrPtr(att->filename), '/');
+ pch = strrchr(ChrPtr(att->FileName), '/');
if (pch != NULL) {
- StrBufCutLeft(att->filename, pch - ChrPtr(att->filename));
+ StrBufCutLeft(att->FileName, pch - ChrPtr(att->FileName));
}
- pch = strrchr(ChrPtr(att->filename), '\\');
+ pch = strrchr(ChrPtr(att->FileName), '\\');
if (pch != NULL) {
- StrBufCutLeft(att->filename, pch - ChrPtr(att->filename));
+ StrBufCutLeft(att->FileName, pch - ChrPtr(att->FileName));
}
/**
* Transfer control of this memory from the upload struct
* to the attachment struct.
*/
- att->data = WCC->upload;
+ att->Data = NewStrBufPlain(WCC->upload, WCC->upload_length);
+ free(WCC->upload);
WCC->upload_length = 0;
WCC->upload = NULL;
display_enter();
* message index functions
*/
+
void DestroyMimeParts(wc_mime_attachment *Mime)
{
FreeStrBuf(&Mime->Name);
/// TODO: check whether we need to load it now?
}
+void tmplput_MIME_LoadData(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+ struct wcsession *WCC = WC;
+ wc_mime_attachment *mime = (wc_mime_attachment*) Context;
+ wc_mime_attachment *att;
+
+ if ( (!strcasecmp(ChrPtr(mime->Disposition), "inline"))||
+ (!strcasecmp(ChrPtr(mime->Disposition), "attachment")) )
+ {
+
+ int n;
+ char N[64];
+ /* steal this mime part... */
+ att = malloc(sizeof(wc_mime_attachment));
+ memcpy(att, mime, sizeof(wc_mime_attachment));
+ memset(mime, 0, sizeof(wc_mime_attachment));
+
+ if (WCC->attachments == NULL)
+ WCC->attachments = NewHash(1, NULL);
+ /* And add it to the list. */
+ n = snprintf(N, sizeof N, "%d", GetCount(WCC->attachments) + 1);
+ Put(WCC->attachments, N, n, att, DestroyMime);
+ }
+}
+
void tmplput_MIME_Length(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
{
wc_mime_attachment *mime = (wc_mime_attachment*) Context;
void tmplput_ATT_Length(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
{
- wc_attachment *att = (wc_attachment*) Context;
+ wc_mime_attachment *att = (wc_mime_attachment*) Context;
StrBufAppendPrintf(Target, "%ld", att->length);
}
void tmplput_ATT_Contenttype(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
{
- wc_attachment *att = (wc_attachment*) Context;
- StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, att->content_type, 0);
+ wc_mime_attachment *att = (wc_mime_attachment*) Context;
+ StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, att->ContentType, 0);
}
void tmplput_ATT_FileName(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
{
- wc_attachment *att = (wc_attachment*) Context;
- StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, att->filename, 0);
+ wc_mime_attachment *att = (wc_mime_attachment*) Context;
+ StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, att->FileName, 0);
}
RegisterNamespace("MAIL:MIME:CHARSET", 0, 2, tmplput_MIME_Charset, CTX_MIME_ATACH);
RegisterNamespace("MAIL:MIME:LENGTH", 0, 2, tmplput_MIME_Length, CTX_MIME_ATACH);
RegisterNamespace("MAIL:MIME:DATA", 0, 2, tmplput_MIME_Data, CTX_MIME_ATACH);
+ RegisterNamespace("MAIL:MIME:LOADDATA", 0, 0, tmplput_MIME_LoadData, CTX_MIME_ATACH);
RegisterIterator("MSG:ATTACHNAMES", 0, NULL, iterate_get_registered_Attachments,
NULL, NULL, CTX_ATT, CTX_NONE);
--- /dev/null
+--------------------------------------------------------------------------------
+<?MAIL:MIME:LOADDATA>
+--------------------------------------------------------------------------------
<?!("COND:MAIL:ANON",2)>***<??("X", 2)>
</span>
<p class="message_subject"><?MAIL:SUMM:SUBJECT></p>
- </div>
+ </div><?ITERATE("MAIL:MIME:ATTACH:ATT", "load_attachments")>
<div class="message_content">
<?MAIL:BODY>
void postpart(StrBuf *partnum, StrBuf *filename, int force_download)
{
void *vPart;
- char content_type[256];
- wc_attachment *part;
+ StrBuf *content_type;
+ wc_mime_attachment *part;
if (GetHash(WC->attachments, SKEY(partnum), &vPart) &&
(vPart != NULL)) {
- part = (wc_attachment*) vPart;
+ part = (wc_mime_attachment*) vPart;
if (force_download) {
- strcpy(content_type, "application/octet-stream");
+ content_type = NewStrBufPlain(HKEY("application/octet-stream"));
}
else {
- strncpy(content_type, ChrPtr(part->content_type), sizeof content_type);
+ content_type = NewStrBufDup(part->ContentType);
}
output_headers(0, 0, 0, 0, 0, 0);
- StrBufAppendBufPlain(WC->WBuf, part->data, part->length, 0);
- http_transmit_thing(content_type, 0);
+ StrBufAppendBuf(WC->WBuf, part->Data, 0);
+ http_transmit_thing(ChrPtr(content_type), 0);
} else {
hprintf("HTTP/1.1 404 %s\n", ChrPtr(partnum));
output_headers(0, 0, 0, 0, 0, 0);
ChrPtr(partnum), ChrPtr(filename));
end_burst();
}
+ FreeStrBuf(&content_type);
}
WCS_LONG /* its an integer */
};
-/*
- * \brief mail attachment ???
- */
-typedef struct _wc_attachment {
- size_t length; /* length of the contenttype */
- StrBuf *content_type; /* the content itself ???*/
- StrBuf *filename; /* the filename hooked to this content ??? */
- char *data; /* the data pool; aka this content */
- long lvalue; /* if we put a long... */
-} wc_attachment;
-void free_attachment(void *vattach);
typedef struct wc_mime_attachment wc_mime_attachment;
StrBuf *Data;
size_t length; /* length of the mimeatachment */
long size_known;
- char content_type[SIZ]; /* the content itself ???*/
- char filename[SIZ]; /* the filename hooked to this content ??? */
- char *data; /* the data pool; aka this content */
long lvalue; /* if we put a long... */
long msgnum; /**< the message number on the citadel server derived from message_summary */
RenderMimeFunc Renderer;