mirror of
https://github.com/deltachat/deltachat-core.git
synced 2025-10-06 03:50:08 +02:00
add a function to get the mime type of a message's file
This commit is contained in:
parent
276daa2614
commit
60572637b3
2 changed files with 43 additions and 2 deletions
44
src/mrmsg.c
44
src/mrmsg.c
|
@ -297,7 +297,7 @@ cleanup:
|
|||
*
|
||||
* @memberof mrmsg_t
|
||||
*
|
||||
* @param msg the message object
|
||||
* @param msg The message object.
|
||||
*
|
||||
* @return base file name plus extension without part. If there is no file
|
||||
* associated with the message, an empty string is returned. The returned
|
||||
|
@ -324,6 +324,46 @@ cleanup:
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get mime type of the file. If there is not file, an empty string is returned.
|
||||
* If there is no associated mime type with the file, the function guesses on; if
|
||||
* in doubt, `application/octet-stream` is returned. NULL is never returned.
|
||||
*
|
||||
* @memberof mrmsg_t
|
||||
*
|
||||
* @param msg The message object.
|
||||
*
|
||||
* @return String containing the mime type. Must be free()'d after usage. NULL is never returned.
|
||||
*/
|
||||
char* mrmsg_get_filemime(mrmsg_t* msg)
|
||||
{
|
||||
char* ret = NULL;
|
||||
char* file = NULL;
|
||||
|
||||
if( msg == NULL ) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = mrparam_get(msg->m_param, MRP_MIMETYPE, NULL);
|
||||
if( ret == NULL ) {
|
||||
int dummy_msgtype = 0;
|
||||
file = mrparam_get(msg->m_param, MRP_FILE, NULL);
|
||||
if( file == NULL ) {
|
||||
goto cleanup;
|
||||
}
|
||||
mrmsg_guess_msgtype_from_suffix(file, &dummy_msgtype, &ret);
|
||||
|
||||
if( ret == NULL ) {
|
||||
ret = safe_strdup("application/octet-stream");
|
||||
}
|
||||
}
|
||||
|
||||
cleanup:
|
||||
free(file);
|
||||
return ret? ret : safe_strdup(NULL);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get real author and title.
|
||||
*
|
||||
|
@ -334,7 +374,7 @@ cleanup:
|
|||
*
|
||||
* @memberof mrmsg_t
|
||||
*
|
||||
* @param msg the message object
|
||||
* @param msg The message object.
|
||||
*
|
||||
* @return mrpoortext_t object that contains the author as mrpoortext_t::m_text1 and the title as mrpoortext_t::m_text2.
|
||||
* Both may be NULL if unknown. The returned object must be freed using mrpoortext_unref() when no longer used.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue