Skip to content
Snippets Groups Projects
Commit c3f7dcc6 authored by rswindell's avatar rswindell
Browse files

Introduce and use convenience pointers for MIME-Version and Content-Type

header fields. Eliminate smb_getcontenttype() - now unnecessary.
parent d182f547
No related branches found
No related tags found
No related merge requests found
......@@ -633,6 +633,8 @@ typedef struct { /* Message */
char* subj; /* Subject */
char* tags; /* Message tags (space-delimited) */
char* editor; /* Message editor (if known) */
char* mime_version; /* MIME Version (if applicable) */
char* content_type; /* MIME Content-Type (if applicable) */
uint16_t to_agent, /* Type of agent message is to */
from_agent, /* Type of agent message is from */
replyto_agent; /* Type of agent replies should be sent to */
......
......@@ -854,6 +854,23 @@ static void set_convenience_ptr(smbmsg_t* msg, uint16_t hfield_type, void* hfiel
case FIDOFLAGS:
msg->ftn_flags=(char*)hfield_dat;
break;
case RFC822HEADER:
{
char* p = (char*)hfield_dat;
if(strnicmp(p, "MIME-Version:", 13) == 0) {
p += 13;
SKIP_WHITESPACE(p);
msg->mime_version = p;
break;
}
if(strnicmp(p, "Content-Type:", 13) == 0) {
p += 13;
SKIP_WHITESPACE(p);
msg->content_type = p;
break;
}
break;
}
}
}
......@@ -884,6 +901,8 @@ static void clear_convenience_ptrs(smbmsg_t* msg)
msg->reverse_path=NULL;
msg->path=NULL;
msg->newsgroups=NULL;
msg->mime_version=NULL;
msg->content_type=NULL;
msg->ftn_msgid=NULL;
msg->ftn_reply=NULL;
......
......@@ -271,7 +271,6 @@ SMBEXPORT void SMBCALL smb_dump_msghdr(FILE* fp, smbmsg_t* msg);
/* smbtxt.c */
SMBEXPORT char* SMBCALL smb_getmsgtxt(smb_t*, smbmsg_t*, ulong mode);
SMBEXPORT char* SMBCALL smb_getplaintext(smbmsg_t*, char* body);
SMBEXPORT char* SMBCALL smb_getcontenttype(smbmsg_t*);
SMBEXPORT uint8_t* SMBCALL smb_getattachment(smbmsg_t*, char* body, char* filename, size_t filename_len, uint32_t* filelen, int index);
SMBEXPORT ulong SMBCALL smb_countattachments(smb_t*, smbmsg_t*, const char* body);
......
......@@ -401,34 +401,16 @@ static char* mime_getcontent(char* buf, const char* content_type, const char* co
return NULL;
}
/* Returns the MIME content-type or NULL if not a MIME-encoded message */
char* SMBCALL smb_getcontenttype(smbmsg_t* msg)
{
int i;
for(i = 0; i < msg->total_hfields; i++) {
if(msg->hfield[i].type == RFC822HEADER) {
if(strnicmp((char*)msg->hfield_dat[i], "Content-Type:", 13) == 0) {
char* result = msg->hfield_dat[i] + 13;
SKIP_WHITESPACE(result);
return result;
}
}
}
return NULL; /* not MIME */
}
/* Get just the plain-text portion of a MIME-encoded message body */
/* Returns NULL if there is no MIME-encoded plain-text portion of the message */
char* SMBCALL smb_getplaintext(smbmsg_t* msg, char* buf)
{
char* txt;
char* content_type = smb_getcontenttype(msg);
enum content_transfer_encoding xfer_encoding = CONTENT_TRANFER_ENCODING_NONE;
if(content_type == NULL) /* not MIME */
if(msg->mime_version == NULL || msg->content_type == NULL) /* not MIME */
return NULL;
txt = mime_getcontent(buf, content_type, "text/plain", 0, &xfer_encoding
txt = mime_getcontent(buf, msg->content_type, "text/plain", 0, &xfer_encoding
,/* attachment: */NULL, /* attachment_len: */0, /* index: */0);
if(txt == NULL)
return NULL;
......@@ -455,12 +437,11 @@ char* SMBCALL smb_getplaintext(smbmsg_t* msg, char* buf)
uint8_t* SMBCALL smb_getattachment(smbmsg_t* msg, char* buf, char* filename, size_t filename_len, uint32_t* filelen, int index)
{
char* txt;
char* content_type = smb_getcontenttype(msg);
enum content_transfer_encoding xfer_encoding = CONTENT_TRANFER_ENCODING_NONE;
if(content_type == NULL) /* not MIME */
if(msg->mime_version == NULL || msg->content_type == NULL) /* not MIME */
return NULL;
txt = mime_getcontent(buf, content_type, /* match-type: */NULL, 0, &xfer_encoding
txt = mime_getcontent(buf, msg->content_type, /* match-type: */NULL, 0, &xfer_encoding
,/* attachment: */filename, filename_len, index);
if(txt != NULL && xfer_encoding == CONTENT_TRANFER_ENCODING_BASE64) {
memmove(buf, txt, strlen(txt)+1);
......@@ -479,9 +460,7 @@ uint8_t* SMBCALL smb_getattachment(smbmsg_t* msg, char* buf, char* filename, siz
/* 'body' may be NULL if the body text is not already read/available */
ulong SMBCALL smb_countattachments(smb_t* smb, smbmsg_t* msg, const char* body)
{
char* content_type = smb_getcontenttype(msg);
if(content_type == NULL) /* not MIME */
if(msg->mime_version == NULL || msg->content_type == NULL) /* not MIME */
return 0;
ulong count = 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment