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