* replace the _pango functions with modest_text_utils_convert_to_pango,
[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 /**
40  * modest_text_utils_derived_subject:
41  * @subject: a string which contains the original subject
42  * @prefix: the prefix for the new subject (such as 'Re:' or 'Fwd:'),
43  *           must not be NULL
44  *
45  * create a 'derived' subject line for eg. replies and forwards 
46  * 
47  * Returns: a newly allocated string containing the resulting subject
48  * subject == NULL, then @prefix " " will be returned
49  */
50 gchar* modest_text_utils_derived_subject (const gchar *subject, 
51                                           const gchar* prefix);
52
53
54 /**
55  * modest_text_utils_quote:
56  * @text: a non-NULL string which contains the message to quote
57  * @from: a non-NULL  sender of the original message
58  * @content_type: the non-NULL content type for the quoting, e.g. "text/html"
59  * @sent_date: sent date/time of the original message
60  * @limit: specifies the maximum characters per line in the quoted text
61  * 
62  * quote an existing message
63  * 
64  * Returns: a newly allocated string containing the quoted message
65  */
66 gchar* modest_text_utils_quote (const gchar *text, 
67                                 const gchar *content_type,
68                                 const gchar *from,
69                                 const time_t sent_date, 
70                                 int limit);
71
72
73 /**
74  * modest_text_utils_cited_text:
75  * @from: sender of the message
76  * @sent_date: the sent date of the original message
77  * @text: the text of the original message
78  *
79  * cite the text in a message
80  * 
81  * Returns: a newly allocated string containing the cited text
82  */
83 gchar* modest_text_utils_cite (const gchar *text,
84                                const gchar *content_type,
85                                const gchar *from,
86                                time_t sent_date);
87
88 /**
89  * modest_text_utils_inlined_text
90  * @from: the non-NULL sender of the original message
91  * @sent_date: sent date/time of the original message
92  * @to: 
93  * @subject: 
94  * @text: 
95  *
96  * creates a new string with the "Original message" text prepended to
97  * the text passed as argument and some data of the header
98  * 
99  * Returns: a newly allocated string containing the quoted message
100  */
101 gchar*   modest_text_utils_inline (const gchar *text,
102                                    const gchar *content_type,
103                                    const gchar *from,
104                                    time_t sent_date,
105                                    const gchar *to,
106                                    const gchar *subject);
107
108 /**
109  * modest_text_utils_remove_address
110  * @address_list: none-NULL string with a comma-separated list of email addresses
111  * @address: an specific e-mail address 
112  *
113  * remove a specific address from a list of email addresses; if @address
114  * is NULL, returns an unchanged @address_list
115  * 
116  * Returns: a newly allocated string containing the new list, or NULL
117  * in case of error or the original @address_list was NULL
118  */
119 gchar*   modest_text_utils_remove_address (const gchar *address_list, 
120                                            const gchar *address);
121
122 /**
123  * modest_text_utils_address_range_at_position:
124  * @address_list: utf8 string containing a list of addresses
125  * @position: a gint
126  * @start: a gint pointer
127  * @end: a gint pointer
128  *
129  * Finds the start and end positions of the address at @position,
130  * in @recipients_list, a list of addresses in the format of a 
131  * recipient list in email. It stores the results in @start and
132  * @end
133  */
134 void     modest_text_utils_address_range_at_position (const gchar *recipients_list,
135                                                       gint position,
136                                                       gint *start,
137                                                       gint *end);
138                                                       
139
140 /**
141  * modest_text_utils_convert_to_html:
142  * @txt: a string
143  *
144  * convert plain text (utf8) into html
145  * 
146  * Returns: a newly allocated string containing the html
147  */
148 gchar*  modest_text_utils_convert_to_html (const gchar *txt);
149
150 /**
151  * modest_text_utils_convert_to_pango:
152  * @txt: a string
153  *
154  * convert plain text (utf8) into pango-escaped text
155  * 
156  * Returns: a newly allocated string containing the html
157  */
158 gchar*  modest_text_utils_convert_to_pango (const gchar *txt);
159
160
161
162
163 /**
164  * modest_text_utils_strftime:
165  * @s:
166  * @max:
167  * @fmt:
168  * @timet:
169  *
170  * this is just an alias for strftime(3), so we can use that without
171  * getting warning from gcc
172  * 
173  * Returns: a formatted string of max length @max in @s
174  */
175 size_t modest_text_utils_strftime(char *s, size_t max, const char  *fmt, time_t timet);
176
177
178
179 /**
180  * modest_text_utils_get_display_addres:
181  * @address: original address (UTF8 string)
182  *
183  * make a 'display address' from an address:
184  * "Foo Bar <foo@bar.cx> (Bla)" --> "Foo Bar"
185  * ie. removes "<...>" and "(...)" parts
186  * the change is in-place; removes leading/trailing whitespace
187  * 
188  * Returns: the new address. The string is *not* newly allocated.
189  * NULL in case of error
190  */
191 gchar* modest_text_utils_get_display_address (gchar *address);
192
193
194 /**
195  * modest_text_utils_get_subject_prefix_len:
196  * @subject: original subject (UTF8 string)
197  *
198  * determine the length of the "Re:/RE:/Fwd:" prefix in an e-mail address
199  * 
200  * Returns: the length of the  prefix, or 0 if there is none
201  */
202 gint modest_text_utils_get_subject_prefix_len (const gchar *subject);
203
204
205 /**
206  * modest_text_utils_utf8_strcmp:
207  * @s1: the first string
208  * @s2: the second string
209  * @insensitive: should the comparison be case-insensitive?
210  *
211  * a strcmp that is NULL-safe, can deal with UTF8 and case-insensitive comparison 
212  *
213  * Returns: an integer less than, equal to, or greater than zero if s1 is found,
214  * respectively, to be less than, to match, or be greater than s2.
215  */
216 gint modest_text_utils_utf8_strcmp (const gchar* s1, const gchar *s2, gboolean insensitive);
217
218
219
220 /**
221  * modest_text_utils_get_display_date:
222  * @date: the date to display
223  *
224  * get a string representation for a date.
225  * 
226  * Returns: the new display date, as a newly allocated string;
227  * free with g_free
228  */
229 gchar* modest_text_utils_get_display_date (time_t date);
230
231
232 /**
233  * modest_text_utils_get_display_size:
234  * @size: size in bytes
235  *
236  * get a string representation for a size in bytes.
237  * 
238  * Returns: the newly allocated display string for the
239  * size in bytes. must be freed.
240  */
241 gchar * modest_text_utils_get_display_size (guint size);
242
243
244 /**
245  * modest_text_utils_validate_email_address:
246  * @email_address: a string
247  * 
248  * validates the email address passed as argument
249  * 
250  * Returns: TRUE if the address is valid, FALSE otherwise
251  **/
252 gboolean     modest_text_utils_validate_email_address (const gchar *email_address);
253
254 /**
255  * modest_text_utils_split_addresses_list:
256  * @addresses: a string
257  *
258  * obtains a GSList of addresses from a string of addresses
259  * in the format understood by email protocols
260  *
261  * Returns: a GSList of strings
262  **/
263 GSList      *modest_text_utils_split_addresses_list (const gchar *addresses);
264
265 #endif /* __MODEST_TEXT_UTILS_H__ */