text
stringlengths
0
357
* @param msg The message object.
* @return 1=Message has location bound to it, 0=No location bound to message.
*/
int dc_msg_has_location(const dc_msg_t* msg)
{
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
return 0;
}
return (msg->location_id!=0);
}
/**
* Get the text of the message.
* If there is no text associated with the message, an empty string is returned.
* NULL is never returned.
*
* The returned text is plain text, HTML is stripped.
* The returned text is truncated to a max. length of currently about 30000 characters,
* it does not make sense to show more text in the message list and typical controls
* will have problems with showing much more text.
* This max. length is to avoid passing _lots_ of data to the frontend which may
* result eg. from decoding errors (assume some bytes missing in a mime structure, forcing
* an attachment to be plain text).
*
* To get information about the message and more/raw text, use dc_get_msg_info().
*
* @memberof dc_msg_t
* @param msg The message object.
* @return Message text. The result must be free()'d. Never returns NULL.
*/
char* dc_msg_get_text(const dc_msg_t* msg)
{
char* ret = NULL;
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
return dc_strdup(NULL);
}
ret = dc_strdup(msg->text);
dc_truncate_str(ret, DC_MAX_GET_TEXT_LEN); /* we do not do this on load: (1) for speed reasons (2) we may decide to process the full text on other places */
return ret;
}
/**
* Find out full path, file name and extension of the file associated with a
* message.
*
* Typically files are associated with images, videos, audios, documents.
* Plain text messages do not have a file.
*
* @memberof dc_msg_t
* @param msg The message object.
* @return Full path, file name and extension of the file associated with the
* message. If there is no file associated with the message, an emtpy
* string is returned. NULL is never returned and the returned value must be free()'d.
*/
char* dc_msg_get_file(const dc_msg_t* msg)
{
char* file_rel = NULL;
char* file_abs = NULL;
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
goto cleanup;
}
if ((file_rel = dc_param_get(msg->param, DC_PARAM_FILE, NULL))!=NULL) {
file_abs = dc_get_abs_path(msg->context, file_rel);
}
cleanup:
free(file_rel);
return file_abs? file_abs : dc_strdup(NULL);
}
/**
* Get base file name without path. The base file name includes the extension; the path
* is not returned. To get the full path, use dc_msg_get_file().
*
* @memberof dc_msg_t
* @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
* value must be free()'d.
*/
char* dc_msg_get_filename(const dc_msg_t* msg)
{
char* ret = NULL;
char* pathNfilename = NULL;
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
goto cleanup;
}
pathNfilename = dc_param_get(msg->param, DC_PARAM_FILE, NULL);
if (pathNfilename==NULL) {
goto cleanup;