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