1/* 2 * Copyright 2011-2016, Haiku, Inc. All rights reserved. 3 * Copyright 2001-2003 Dr. Zoidberg Enterprises. All rights reserved. 4 */ 5#ifndef ZOIDBERG_GARGOYLE_MAIL_UTIL_H 6#define ZOIDBERG_GARGOYLE_MAIL_UTIL_H 7 8 9//! Header parsing utilities 10 11 12#include <stdio.h> 13 14#include <DataIO.h> 15#include <E-mail.h> 16#include <Message.h> 17#include <Node.h> 18 19 20// TODO: this should only be preserved for gcc2 compatibility 21 22 23class BString; 24 25 26status_t write_read_attr(BNode& node, read_flags flag); 27status_t read_read_attr(BNode& node, read_flags& flag); 28 29 30// The next couple of functions are our wrapper around convert_to_utf8 and 31// convert_from_utf8 so that they can also convert from UTF-8 to UTF-8 by 32// specifying the MDR_UTF8_CONVERSION constant as the conversion operation. 33 34status_t mail_convert_to_utf8(uint32 srcEncoding, const char *src, 35 int32 *srcLen, char *dst, int32 *dstLen, int32 *state, 36 char substitute = B_SUBSTITUTE); 37 38status_t mail_convert_from_utf8(uint32 dstEncoding, const char *src, 39 int32 *srcLen, char *dst, int32 *dstLen, int32 *state, 40 char substitute = B_SUBSTITUTE); 41 42 43void trim_white_space(BString &string); 44// Remove leading and trailing white space from the string. 45 46void SubjectToThread(BString &string); 47// Convert a subject to the core words (remove the extraneous RE: re: etc). 48 49time_t ParseDateWithTimeZone(const char *DateString); 50// Converts a date to a time. Handles time zones too, unlike parsedate. 51 52ssize_t rfc2047_to_utf8(char **buffer, size_t *bufLen, size_t strLen = 0); 53ssize_t utf8_to_rfc2047(char **bufp, ssize_t length,uint32 charset, char encoding); 54// convert (in place) RFC 2047-style escape sequences ("=?...?.?...?=") 55// in the first strLen characters of *buffer into UTF-8, and return the 56// length of the converted string or an error code less than 0 on error. 57// 58// This may cause the string to grow. If it grows bigger than *bufLen, 59// *buffer will be reallocated using realloc(), and its new length stored 60// in *bufLen. 61// 62// Unidentified charsets and conversion errors cause 63// the offending text to be skipped. 64 65void FoldLineAtWhiteSpaceAndAddCRLF(BString &string); 66// Insert CRLF at various spots in the given string (before white space) so 67// that the line length is mostly under 78 bytes. Also makes sure there is a 68// CRLF at the very end. 69 70ssize_t nextfoldedline(const char** header, char **buffer, size_t *buflen); 71ssize_t readfoldedline(FILE *file, char **buffer, size_t *buflen); 72ssize_t readfoldedline(BPositionIO &in, char **buffer, size_t *buflen); 73// Return in *buffer a \n-terminated line (even if the original is \r\n 74// terminated or not terminated at all (last line in file situation)) from a 75// memory buffer, FILE* or BPositionIO, after folding \r?\n(\s)->$1. Return 76// the length of the folded string directly, or a negative error code if there 77// was a memory allocation error or file read error. It will return zero only 78// when trying to read at end of file. *header, *file and &in are left 79// pointing to the first character after the line read. 80// 81// if buffer is not NULL return a pointer to the buffer in *buffer 82// if *buffer is not NULL, use the preallocated buffer, though it may get 83// realloc'd (so use malloc to allocate it and expect to have your *buffer 84// pointer modified to point to the new buffer if a realloc happens). 85// if buflen is not NULL, return the final size of the buffer in buflen 86// if buffer is not NULL, buflen is not NULL, and *buffer is not NULL 87// *buffer is a buffer of size *buflen 88// if buffer is NULL or *buffer is NULL, and buflen is not NULL then 89// start with a buffer of size *buflen 90 91status_t parse_header(BMessage &headers, BPositionIO &input); 92status_t extract_from_header(const BString& header, const BString& field, 93 BString& target); 94 95void extract_address(BString &address); 96 // retrieves the mail address only from an address header formatted field 97 98void extract_address_name(BString &address); 99 // Given a header field (usually the From: e-mail address) with gobbledygook in 100 // it, find the longest human-readable phrase (usually the person's name). 101 102void get_address_list(BList &list, const char *string, 103 void (*cleanupFunc)(BString &) = NULL); 104 105status_t CopyMailFolderAttributes(const char* targetPath); 106 107 108#endif /* ZOIDBERG_GARGOYLE_MAIL_UTIL_H */ 109