2 * Copyright 2011-2016, Haiku, Inc. All rights reserved.
3 * Copyright 2001-2003 Dr. Zoidberg Enterprises. All rights reserved.
5 #ifndef ZOIDBERG_GARGOYLE_MAIL_UTIL_H
6 #define ZOIDBERG_GARGOYLE_MAIL_UTIL_H
9 //! Header parsing utilities
20 // TODO: this should only be preserved for gcc2 compatibility
26 status_t
write_read_attr(BNode
& node
, read_flags flag
);
27 status_t
read_read_attr(BNode
& node
, read_flags
& flag
);
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.
34 status_t
mail_convert_to_utf8(uint32 srcEncoding
, const char *src
,
35 int32
*srcLen
, char *dst
, int32
*dstLen
, int32
*state
,
36 char substitute
= B_SUBSTITUTE
);
38 status_t
mail_convert_from_utf8(uint32 dstEncoding
, const char *src
,
39 int32
*srcLen
, char *dst
, int32
*dstLen
, int32
*state
,
40 char substitute
= B_SUBSTITUTE
);
43 void trim_white_space(BString
&string
);
44 // Remove leading and trailing white space from the string.
46 void SubjectToThread(BString
&string
);
47 // Convert a subject to the core words (remove the extraneous RE: re: etc).
49 time_t ParseDateWithTimeZone(const char *DateString
);
50 // Converts a date to a time. Handles time zones too, unlike parsedate.
52 ssize_t
rfc2047_to_utf8(char **buffer
, size_t *bufLen
, size_t strLen
= 0);
53 ssize_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.
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
62 // Unidentified charsets and conversion errors cause
63 // the offending text to be skipped.
65 void 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.
70 ssize_t
nextfoldedline(const char** header
, char **buffer
, size_t *buflen
);
71 ssize_t
readfoldedline(FILE *file
, char **buffer
, size_t *buflen
);
72 ssize_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.
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
91 status_t
parse_header(BMessage
&headers
, BPositionIO
&input
);
92 status_t
extract_from_header(const BString
& header
, const BString
& field
,
95 void extract_address(BString
&address
);
96 // retrieves the mail address only from an address header formatted field
98 void 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).
102 void get_address_list(BList
&list
, const char *string
,
103 void (*cleanupFunc
)(BString
&) = NULL
);
105 status_t
CopyMailFolderAttributes(const char* targetPath
);
108 #endif /* ZOIDBERG_GARGOYLE_MAIL_UTIL_H */