summaryrefslogtreecommitdiffstats
path: root/sqwebmail/msg2html.h
blob: 331ec9ed53945177a6e6af6718d40b218c929234 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#ifndef msg2html_h
#define msg2html_h

#include "config.h"
#include "rfc822/rfc822.h"
#include "rfc2045/rfc2045.h"

#include <stdio.h>
#include <string.h>

struct msg2html_smiley_list {
	struct msg2html_smiley_list *next;
	char *code;
	char *url;
};


struct msg2html_info {
	const char *output_character_set;
	/* Required - generate output in this character set */

	void *arg; /* Passthrough parameter to callback functions */

	const char *mimegpgfilename;
	/*
	** If not NULL, msg2html() receives GPG-decoded message read from
	** mimegpgfilename.  The contents of mimegpgfilename are blindly
	** appended to href links to multipart/related content.
	*/

	const char *gpgdir;
	/*
	** If not NULL -- points to the .gpg configuration directory.
	*/

	int fullheaders; /* Flag: show all headers */

	int noflowedtext; /* Flag: do not show flowed text */

	int showhtml; /* Flag: show HTML content */

	int is_gpg_enabled;
	/* True: check for decrypted content, and format it accordingly */

	int is_preview_mode;
	/* True: sqwebmail is showing a draft message in preview mode */

	char *(*get_url_to_mime_part)(const char *mimeid,
				      void *arg);
	/*
	** Return a malloced buffer with a URL that would point to the
	** message's indicated MIME part.
	*/

	void (*charset_warning)(const char *, void *);
	/* If not NULL - content in this character set could not be converted */

	void (*html_content_follows)();
	/* If not NULL - HTML content follows */

	const char *wash_http_prefix;
	/* Prepended to http: URLs, which get encoded */

	const char *wash_mailto_prefix;
	/* Prepended to mailto: URLs */

	void (*message_rfc822_action)(struct rfc2045id *idptr);
	/*
	** idpart references a message/rfc822 attachment.  Emit HTML
	** for the usual actions (reply, forward, etc...)
	*/

	void (*inline_image_action)(struct rfc2045id *idptr,
				    const char *content_type,
				    void *arg);
	/* Inline image attachment */

	void (*application_pgp_keys_action)(struct rfc2045id *id);
	/* Attached PGP keys */

	void (*unknown_attachment_action)(struct rfc2045id *idptr,
					  const char *content_type,
					  const char *content_name,
					  off_t size,
					  void *arg);

	void (*gpg_message_action)();
	/*
	** This message contains MIME/PGP content.  Post the appropriate
	** notice.
	*/

	/* Mark the beginning and end of an E-mail address in mail headers: */
	void (*email_address_start)(const char *name, const char *addr);
	void (*email_address_end)();

	/*
	** Format a mail header. (*format_header) should invoke
	** (*cb_func) with a pointer to whatever should be displayed, which
	** may be just hdrname (which is the default behavior.
	*/

	void (*email_header)(const char *hdrname,
			     void (*cb_func)(const char *));

	/*
	** Return strftime() format string for dates. 'def' is the
	** proposed default.  The default implementation simply returns
	** the default string.
	*/

	const char *(*email_header_date_fmt)(const char *def);

	/*
	** Return HTML code for rendering a URL, if the URL scheme is
	** recognized.  The HTML code is returned in an malloc-ed buffer:
	*/
	char *(*get_textlink)(const char *url, void *arg);

	struct msg2html_smiley_list *smileys;
	char smiley_index[50];
};

struct msg2html_info *msg2html_alloc(const char *charset);
void msg2html_add_smiley(struct msg2html_info *i,
			 const char *txt, const char *imgurl);

void msg2html_free(struct msg2html_info *);

void msg2html(FILE *fp, struct rfc2045 *rfc, struct msg2html_info *info);

void msg2html_download(FILE *fp, const char *mimeid, int dodownload,
		       const char *system_charset);

void msg2html_showmimeid(struct rfc2045id *idptr, const char *p);

/*
** INTERNAL
*/

struct msg2html_textplain_info;

struct msg2html_textplain_info *
msg2html_textplain_start(const char *message_charset,
			 const char *output_character_set,
			 int isflowed,
			 int isdelsp,
			 int isdraft,
			 char *(*get_textlink)(const char *url, void *arg),
			 void *get_textlink_arg,

			 const char *smiley_index,
			 struct msg2html_smiley_list *smileys,
			 int wikifmt,

			 void (*output_func)(const char *p,
					     size_t n, void *arg),
			 void *arg);

void msg2html_textplain(struct msg2html_textplain_info *info,
			const char *ptr,
			size_t cnt);

int msg2html_textplain_end(struct msg2html_textplain_info *info);

#endif