xref: /haiku/headers/os/mail/E-mail.h (revision 4f00613311d0bd6b70fa82ce19931c41f071ea4e)
1 /*******************************************************************************
2 /
3 /	File:		E-mail.h
4 /
5 /	Description:	Mail attributes and BMailMessage class.
6 /
7 /	Copyright 1993-98, Be Incorporated, All Rights Reserved.
8 /
9 *******************************************************************************/
10 
11 #ifndef _E_MAIL_H
12 #define _E_MAIL_H
13 
14 #include <UTF8.h>
15 
16 class BList;
17 
18 /* -----------------------------------------------------------------------*/
19 /* 'E-Mail' attributes...*/
20 
21 #define B_MAIL_ATTR_NAME		"MAIL:name"			/* indexed string*/
22 #define B_MAIL_ATTR_STATUS		"MAIL:status"		/* indexed string*/
23 #define B_MAIL_ATTR_PRIORITY	"MAIL:priority"		/* indexed string*/
24 #define B_MAIL_ATTR_TO			"MAIL:to"			/* indexed string*/
25 #define B_MAIL_ATTR_CC			"MAIL:cc"			/* indexed string*/
26 #define B_MAIL_ATTR_FROM		"MAIL:from"			/* indexed string*/
27 #define B_MAIL_ATTR_SUBJECT		"MAIL:subject"		/* indexed string*/
28 #define B_MAIL_ATTR_REPLY		"MAIL:reply"		/* indexed string*/
29 #define B_MAIL_ATTR_WHEN		"MAIL:when"			/* indexed time*/
30 #define B_MAIL_ATTR_FLAGS		"MAIL:flags"		/* indexed int32*/
31 #define B_MAIL_ATTR_RECIPIENTS	"MAIL:recipients"	/* string*/
32 #define B_MAIL_ATTR_MIME		"MAIL:mime"			/* string*/
33 #define B_MAIL_ATTR_HEADER		"MAIL:header_length"	/* int32*/
34 #define B_MAIL_ATTR_CONTENT		"MAIL:content_length"	/* int32*/
35 
36 
37 /* mail flags */
38 enum	mail_flags			{B_MAIL_PENDING	= 1,	/* waiting to be sent*/
39 							 B_MAIL_SENT	= 2,	/* has been sent*/
40 							 B_MAIL_SAVE	= 4};	/* save mail after sending*/
41 
42 #define B_MAIL_TYPE			"text/x-email"			/* mime type*/
43 
44 /* Everything past this point is deprecated. See MailMessage.h, mail_encoding.h
45 	and MailDaemon.h for alternatives. */
46 
47 /* DEPRECATED -- DEPRECATED -- DEPRECATED -- DEPRECATED -- DEPRECATED */
48 /* DEPRECATED -- DEPRECATED -- DEPRECATED -- DEPRECATED -- DEPRECATED */
49 
50 /* defines...*/
51 
52 /* schedule days */
53 #define B_CHECK_NEVER			 0
54 #define B_CHECK_WEEKDAYS		 1
55 #define B_CHECK_DAILY			 2
56 #define B_CHECK_CONTINUOUSLY	 3
57 #define B_CHECK_CONTINUOSLY		 3
58 
59 /* max. lengths */
60 #define B_MAX_USER_NAME_LENGTH	32
61 #define B_MAX_HOST_NAME_LENGTH	64
62 
63 /* rfc822 header field types */
64 #define B_MAIL_TO			"To: "
65 #define B_MAIL_CC			"Cc: "
66 #define B_MAIL_BCC			"Bcc: "
67 #define B_MAIL_FROM			"From: "
68 #define B_MAIL_DATE			"Date: "
69 #define B_MAIL_REPLY		"Reply-To: "
70 #define B_MAIL_SUBJECT		"Subject: "
71 #define B_MAIL_PRIORITY		"Priority: "
72 
73 
74 /* -----------------------------------------------------------------------*/
75 /* structs...*/
76 
77 typedef struct {
78 	char		pop_name[B_MAX_USER_NAME_LENGTH];
79 	char		pop_password[B_MAX_USER_NAME_LENGTH];
80 	char		pop_host[B_MAX_HOST_NAME_LENGTH];
81 	char		real_name[128];
82 	char		reply_to[128];
83 	int32		days;			/* see flags above*/
84 	int32		interval;		/* in seconds*/
85 	int32		begin_time;		/* in seconds*/
86 	int32		end_time;		/* in seconds*/
87 } mail_pop_account;
88 
89 typedef struct {
90 	bool		alert;
91 	bool		beep;
92 } mail_notification;
93 
94 /* -----------------------------------------------------------------------*/
95 /* global functions...*/
96 
97 _IMPEXP_MAIL int32		count_pop_accounts(void);
98 _IMPEXP_MAIL status_t	get_pop_account(mail_pop_account*, int32 index = 0);
99 _IMPEXP_MAIL status_t	set_pop_account(mail_pop_account*, int32 index = 0,
100 							bool save = true);
101 _IMPEXP_MAIL status_t	get_smtp_host(char*);
102 _IMPEXP_MAIL status_t	set_smtp_host(char*, bool save = true);
103 _IMPEXP_MAIL status_t	get_mail_notification(mail_notification*);
104 _IMPEXP_MAIL status_t	set_mail_notification(mail_notification*, bool save = true);
105 
106 _IMPEXP_MAIL status_t	check_for_mail(int32 *incoming_count = NULL);
107 _IMPEXP_MAIL status_t	send_queued_mail(void);
108 _IMPEXP_MAIL status_t	forward_mail(entry_ref*, const char* recipients, bool now = true);
109 
110 _IMPEXP_MAIL ssize_t	decode_base64(char *out, char *in, off_t length,
111 							bool replace_cr = false);
112 _IMPEXP_MAIL ssize_t	encode_base64(char *out, char *in, off_t length);
113 
114 
115 /* -----------------------------------------------------------------------*/
116 /* class...*/
117 
118 class BMailMessage {
119 
120 public:
121 					BMailMessage(void);
122 					~BMailMessage(void);
123 
124 		status_t	AddContent(const char *text, int32 length,
125 							   uint32 encoding = B_ISO1_CONVERSION,
126 							   bool clobber = false);
127 		status_t	AddContent(const char *text, int32 length,
128 							   const char *encoding, bool clobber = false);
129 
130 		status_t	AddEnclosure(entry_ref *ref, bool clobber = false);
131 		status_t	AddEnclosure(const char *path, bool clobber = false);
132 		status_t	AddEnclosure(const char *MIME_type, void *data, int32 len,
133 								 bool clobber = false);
134 
135 		status_t	AddHeaderField(uint32 encoding, const char *field_name, const char *str,
136 								   bool clobber = false);
137 		status_t	AddHeaderField(const char *field_name, const char *str,
138 								   bool clobber = false);
139 
140 		status_t	Send(bool send_now = false,
141 						 bool remove_when_I_have_completed_sending_this_message_to_your_preferred_SMTP_server = false);
142 
143 
144 /* -----------------------------------------------------------------------*/
145 
146 private:
147 		BList*		fFields;
148 		bool		fMultiPart;
149 
150 		int32		concatinate(char**, int32, char*);
151 		int32		count_fields(char *name = NULL);
152 		status_t	find_field(char*, type_code*, char**, void**, int32*,
153 							   uint32*, char**, bool*, int32);
154 		BList*		find_field(const char*);
155 		status_t	get_field_name(char**, int32);
156 		status_t	set_field(const char*, type_code, const char*, const void*,
157 							  int32, uint32, const char*, bool);
158 };
159 
160 #endif /* _MAIL_H */
161