d8963465149628e05f5ddc726615a17107388cb1
[modest] / src / modest-text-utils.h
1 /* Copyright (c) 2006, Nokia Corporation
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  *   notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  *   notice, this list of conditions and the following disclaimer in the
12  *   documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Nokia Corporation nor the names of its
14  *   contributors may be used to endorse or promote products derived from
15  *   this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30
31 /* modest-text-utils.h */
32
33 #ifndef __MODEST_TEXT_UTILS_H__
34 #define __MODEST_TEXT_UTILS_H__
35
36 #include <time.h>
37 #include <glib.h>
38
39 #define _FM(str) dgettext("hildon-fm",str)
40
41 /**
42  * modest_text_utils_derived_subject:
43  * @subject: a string which contains the original subject
44  * @prefix: the prefix for the new subject (such as 'Re:' or 'Fwd:'),
45  *           must not be NULL
46  *
47  * create a 'derived' subject line for eg. replies and forwards 
48  * 
49  * Returns: a newly allocated string containing the resulting subject
50  * subject == NULL, then @prefix " " will be returned
51  */
52 gchar* modest_text_utils_derived_subject (const gchar *subject, 
53                                           const gchar* prefix);
54
55
56 /**
57  * modest_text_utils_quote:
58  * @text: a non-NULL string which contains the message to quote
59  * @from: a non-NULL  sender of the original message
60  * @content_type: the non-NULL content type for the quoting, e.g. "text/html"
61  * @signature: NULL or the signature to add
62  * @sent_date: sent date/time of the original message
63  * @limit: specifies the maximum characters per line in the quoted text
64  * 
65  * quote an existing message
66  * 
67  * Returns: a newly allocated string containing the quoted message
68  */
69 gchar* modest_text_utils_quote (const gchar *text, 
70                                 const gchar *content_type,
71                                 const gchar *signature,
72                                 const gchar *from,
73                                 const time_t sent_date, 
74                                 int limit);
75
76
77 /**
78  * modest_text_utils_cited_text:
79  * @from: sender of the message
80  * @sent_date: the sent date of the original message
81  * @text: the text of the original message
82  *
83  * cite the text in a message
84  * 
85  * Returns: a newly allocated string containing the cited text
86  */
87 gchar* modest_text_utils_cite (const gchar *text,
88                                const gchar *content_type,
89                                const gchar *signature,
90                                const gchar *from,
91                                time_t sent_date);
92
93 /**
94  * modest_text_utils_inlined_text
95  * @from: the non-NULL sender of the original message
96  * @sent_date: sent date/time of the original message
97  * @to: 
98  * @subject: 
99  * @text: 
100  *
101  * creates a new string with the "Original message" text prepended to
102  * the text passed as argument and some data of the header
103  * 
104  * Returns: a newly allocated string containing the quoted message
105  */
106 gchar*   modest_text_utils_inline (const gchar *text,
107                                    const gchar *content_type,
108                                    const gchar *signature,
109                                    const gchar *from,
110                                    time_t sent_date,
111                                    const gchar *to,
112                                    const gchar *subject);
113
114 /**
115  * modest_text_utils_remove_address
116  * @address_list: none-NULL string with a comma-separated list of email addresses
117  * @address: an specific e-mail address 
118  *
119  * remove a specific address from a list of email addresses; if @address
120  * is NULL, returns an unchanged @address_list
121  * 
122  * Returns: a newly allocated string containing the new list, or NULL
123  * in case of error or the original @address_list was NULL
124  */
125 gchar*   modest_text_utils_remove_address (const gchar *address_list, 
126                                            const gchar *address);
127
128 /**
129  * modest_text_utils_address_range_at_position:
130  * @address_list: utf8 string containing a list of addresses
131  * @position: a gint
132  * @start: a gint pointer
133  * @end: a gint pointer
134  *
135  * Finds the start and end positions of the address at @position,
136  * in @recipients_list, a list of addresses in the format of a 
137  * recipient list in email. It stores the results in @start and
138  * @end
139  */
140 void     modest_text_utils_address_range_at_position (const gchar *recipients_list,
141                                                       gint position,
142                                                       gint *start,
143                                                       gint *end);
144                                                       
145
146 /**
147  * modest_text_utils_convert_to_html:
148  * @txt: a string
149  *
150  * convert plain text (utf8) into html
151  * 
152  * Returns: a newly allocated string containing the html
153  */
154 gchar*  modest_text_utils_convert_to_html (const gchar *txt);
155
156 /**
157  * modest_text_utils_convert_to_html_body:
158  * @txt: a string
159  *
160  * convert plain text (utf8) into html without adding html headers.
161  * 
162  * Returns: a newly allocated string containing the html
163  */
164 gchar*  modest_text_utils_convert_to_html_body (const gchar *data);
165
166
167 /**
168  * modest_text_utils_strftime:
169  * @s:
170  * @max:
171  * @fmt:
172  * @timet:
173  *
174  * this is just an alias for strftime(3), so we can use that without
175  * getting warning from gcc
176  * 
177  * Returns: a formatted string of max length @max in @s
178  */
179 size_t modest_text_utils_strftime(char *s, size_t max, const char  *fmt, time_t timet);
180
181
182
183 /**
184  * modest_text_utils_get_display_addres:
185  * @address: original address (UTF8 string)
186  *
187  * make a 'display address' from an address:
188  * "Foo Bar <foo@bar.cx> (Bla)" --> "Foo Bar"
189  * ie. removes "<...>" and "(...)" parts
190  * the change is in-place; removes leading/trailing whitespace
191  * 
192  * Returns: the new address of the string; this new string
193  * is _NOT_ newly allocated, so should not be freed. (remember
194  * the old address of the parameter if that one needs to be freed)
195  * 
196  * NULL in case of error or if address == NULL
197  */
198 gchar* modest_text_utils_get_display_address (gchar *address);
199
200
201 /**
202  * modest_text_utils_get_subject_prefix_len:
203  * @subject: original subject (UTF8 string)
204  *
205  * determine the length of the "Re:/RE:/Fwd:" prefix in an e-mail address
206  * 
207  * Returns: the length of the  prefix, or 0 if there is none
208  */
209 gint modest_text_utils_get_subject_prefix_len (const gchar *subject);
210
211
212 /**
213  * modest_text_utils_utf8_strcmp:
214  * @s1: the first string
215  * @s2: the second string
216  * @insensitive: should the comparison be case-insensitive?
217  *
218  * a strcmp that is NULL-safe, can deal with UTF8 and case-insensitive comparison 
219  *
220  * Returns: an integer less than, equal to, or greater than zero if s1 is found,
221  * respectively, to be less than, to match, or be greater than s2.
222  */
223 gint modest_text_utils_utf8_strcmp (const gchar* s1, const gchar *s2, gboolean insensitive);
224
225
226
227 /**
228  * modest_text_utils_get_display_date:
229  * @date: the date to display
230  *
231  * get a string representation for a date.
232  * 
233  * Returns: the new display date, as a newly allocated string;
234  * free with g_free
235  */
236 gchar* modest_text_utils_get_display_date (time_t date);
237
238
239 /**
240  * modest_text_utils_get_display_size:
241  * @size: size in bytes
242  *
243  * get a string representation for a size in bytes.
244  * 
245  * Returns: the newly allocated display string for the
246  * size in bytes. must be freed.
247  */
248 gchar * modest_text_utils_get_display_size (guint64 size);
249
250
251 /**
252  * modest_text_utils_validate_email_address:
253  * @email_address: a string
254  * 
255  * validates the email address passed as argument
256  * 
257  * Returns: TRUE if the address is valid, FALSE otherwise
258  **/
259 gboolean     modest_text_utils_validate_email_address (const gchar *email_address);
260
261 /**
262  * modest_text_utils_validate_recipient:
263  * @recipient: a string
264  *
265  * validates @recipient as a valid recipient field for header.
266  * It's different from modest_text_utils_validate_email_address()
267  * as it validates a whole recipient, and not only the part between
268  * the &lt; and &gt; symbols.
269  *
270  * Returns: %TRUE if the recipient is valid, FALSE otherwise
271  **/
272 gboolean     modest_text_utils_validate_recipient (const gchar *recipient);
273
274 /**
275  * modest_text_utils_split_addresses_list:
276  * @addresses: a string
277  *
278  * obtains a GSList of addresses from a string of addresses
279  * in the format understood by email protocols
280  *
281  * Returns: a GSList of strings
282  **/
283 GSList      *modest_text_utils_split_addresses_list (const gchar *addresses);
284
285 /**
286  * modest_text_utils_get_addresses_indexes:
287  * @addresses: a string
288  * @start_indexes: a #GSList pointer
289  * @end_indexes: a #GSList pointer
290  *
291  * obtains two #GSList of @addresses with the range offsets of the addresses in
292  * the string
293  *
294  * Returns: a GSList of strings
295  **/
296 void         modest_text_utils_get_addresses_indexes (const gchar *addresses, GSList **start_indexes, GSList **end_indexes);
297
298 #endif /* __MODEST_TEXT_UTILS_H__ */