Commit 3d81ec01 authored by rswindell's avatar rswindell
Browse files

smb_getplaintext() now returns NULL if there is no MIME-encoded plain-text.

This allows a message displayer to indicate to the user that some MIME-decoding
took place.
parent c87e337c
...@@ -184,8 +184,11 @@ char* SMBCALL smb_getmsgtxt(smb_t* smb, smbmsg_t* msg, ulong mode) ...@@ -184,8 +184,11 @@ char* SMBCALL smb_getmsgtxt(smb_t* smb, smbmsg_t* msg, ulong mode)
*(buf+l)=0; *(buf+l)=0;
} }
if(mode&GETMSGTXT_PLAIN) if(mode&GETMSGTXT_PLAIN) {
buf = smb_getplaintext(msg, buf); char* plaintext = smb_getplaintext(msg, buf);
if(plaintext != NULL)
return plaintext;
}
return(buf); return(buf);
} }
...@@ -381,6 +384,7 @@ static char* mime_getcontent(char* buf, const char* content_type, const char* co ...@@ -381,6 +384,7 @@ static char* mime_getcontent(char* buf, const char* content_type, const char* co
} }
/* Get just the plain-text portion of a MIME-encoded message body */ /* 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* SMBCALL smb_getplaintext(smbmsg_t* msg, char* buf)
{ {
int i; int i;
...@@ -397,23 +401,24 @@ char* SMBCALL smb_getplaintext(smbmsg_t* msg, char* buf) ...@@ -397,23 +401,24 @@ char* SMBCALL smb_getplaintext(smbmsg_t* msg, char* buf)
} }
} }
if(content_type == NULL) /* not MIME */ if(content_type == NULL) /* not MIME */
return buf; return NULL;
txt = mime_getcontent(buf, content_type, "text/plain", 0, &xfer_encoding txt = mime_getcontent(buf, content_type, "text/plain", 0, &xfer_encoding
,/* attachment: */NULL, /* index: */0); ,/* attachment: */NULL, /* index: */0);
if(txt != NULL) { if(txt == NULL)
memmove(buf, txt, strlen(txt)+1); return NULL;
if(*buf == 0)
return buf; memmove(buf, txt, strlen(txt)+1);
if(xfer_encoding == CONTENT_TRANFER_ENCODING_QUOTED_PRINTABLE) if(*buf == 0) /* No decoding necessary */
qp_decode(buf); return buf;
else if(xfer_encoding == CONTENT_TRANFER_ENCODING_BASE64) { if(xfer_encoding == CONTENT_TRANFER_ENCODING_QUOTED_PRINTABLE)
char* decoded = strdup(buf); qp_decode(buf);
if(decoded == NULL) else if(xfer_encoding == CONTENT_TRANFER_ENCODING_BASE64) {
return buf; char* decoded = strdup(buf);
if(b64_decode(decoded, strlen(decoded), buf, strlen(buf)) > 0) if(decoded == NULL)
strcpy(buf, decoded); return NULL;
free(decoded); if(b64_decode(decoded, strlen(decoded), buf, strlen(buf)) > 0)
} strcpy(buf, decoded);
free(decoded);
} }
return buf; return buf;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment