vfs: check userland buffers before reading them.
[haiku.git] / headers / os / mail / E-mail.h
blob8054faa83178d47e6d34edf49064f04a8ddfc586
1 /*
2 * Copyright 2009, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef _E_MAIL_H
6 #define _E_MAIL_H
9 #include <UTF8.h>
12 class BList;
13 struct entry_ref;
16 // E-Mail attributes
17 #define B_MAIL_ATTR_NAME "MAIL:name" // indexed string
18 #define B_MAIL_ATTR_STATUS "MAIL:status" // indexed string
19 #define B_MAIL_ATTR_PRIORITY "MAIL:priority" // indexed string
20 #define B_MAIL_ATTR_TO "MAIL:to" // indexed string
21 #define B_MAIL_ATTR_CC "MAIL:cc" // indexed string
22 #define B_MAIL_ATTR_BCC "MAIL:bcc" // string
23 #define B_MAIL_ATTR_FROM "MAIL:from" // indexed string
24 #define B_MAIL_ATTR_SUBJECT "MAIL:subject" // indexed string
25 #define B_MAIL_ATTR_REPLY "MAIL:reply" // indexed string
26 #define B_MAIL_ATTR_WHEN "MAIL:when" // indexed time
27 #define B_MAIL_ATTR_FLAGS "MAIL:flags" // indexed int32
28 #define B_MAIL_ATTR_RECIPIENTS "MAIL:recipients" // string
29 #define B_MAIL_ATTR_MIME "MAIL:mime" // string
30 #define B_MAIL_ATTR_HEADER "MAIL:header_length" // int32
31 #define B_MAIL_ATTR_CONTENT "MAIL:content_length" // int32
32 #define B_MAIL_ATTR_READ "MAIL:read" // int32
33 #define B_MAIL_ATTR_THREAD "MAIL:thread" // string
34 #define B_MAIL_ATTR_ACCOUNT "MAIL:account" // string
35 #define B_MAIL_ATTR_ACCOUNT_ID "MAIL:account_id" // int32
38 // read flags
39 enum read_flags {
40 B_UNREAD = 0,
41 B_SEEN = 1,
42 B_READ = 2
47 // mail flags
48 enum mail_flags {
49 B_MAIL_PENDING = 1, // waiting to be sent
51 B_MAIL_SENT = 2, // has been sent
53 B_MAIL_SAVE = 4 // save mail after
54 // sending
57 #define B_MAIL_TYPE "text/x-email" // mime type
58 #define B_PARTIAL_MAIL_TYPE "text/x-partial-email" // mime type
61 // WARNING: Everything past this point is deprecated. See MailMessage.h,
62 // mail_encoding.h and MailDaemon.h for alternatives.
65 // #pragma mark - defines
67 // schedule days
68 #define B_CHECK_NEVER 0
69 #define B_CHECK_WEEKDAYS 1
70 #define B_CHECK_DAILY 2
71 #define B_CHECK_CONTINUOUSLY 3
72 #define B_CHECK_CONTINUOSLY 3
74 // max. lengths
75 #define B_MAX_USER_NAME_LENGTH 32
76 #define B_MAX_HOST_NAME_LENGTH 64
78 // rfc822 header field types
79 #define B_MAIL_TO "To: "
80 #define B_MAIL_CC "Cc: "
81 #define B_MAIL_BCC "Bcc: "
82 #define B_MAIL_FROM "From: "
83 #define B_MAIL_DATE "Date: "
84 #define B_MAIL_REPLY "Reply-To: "
85 #define B_MAIL_SUBJECT "Subject: "
86 #define B_MAIL_PRIORITY "Priority: "
89 // #pragma mark - structs
92 typedef struct {
93 char pop_name[B_MAX_USER_NAME_LENGTH];
94 char pop_password[B_MAX_USER_NAME_LENGTH];
95 char pop_host[B_MAX_HOST_NAME_LENGTH];
96 char real_name[128];
97 char reply_to[128];
98 int32 days; /* see flags above*/
99 int32 interval; /* in seconds*/
100 int32 begin_time; /* in seconds*/
101 int32 end_time; /* in seconds*/
102 } mail_pop_account;
104 typedef struct {
105 bool alert;
106 bool beep;
107 } mail_notification;
110 // #pragma mark - global functions
112 int32 count_pop_accounts(void);
113 status_t get_pop_account(mail_pop_account*, int32 index = 0);
114 status_t set_pop_account(mail_pop_account*, int32 index = 0,
115 bool save = true);
118 // #pragma mark - BMailMessage
120 class BMailMessage {
121 public:
122 BMailMessage();
123 ~BMailMessage();
125 status_t AddContent(const char* text, int32 length,
126 uint32 encoding = B_ISO1_CONVERSION,
127 bool clobber = false);
128 status_t AddContent(const char* text, int32 length,
129 const char* encoding,
130 bool clobber = false);
132 status_t AddEnclosure(entry_ref* ref,
133 bool clobber = false);
134 status_t AddEnclosure(const char* path,
135 bool clobber = false);
136 status_t AddEnclosure(const char* MIME_type, void* data,
137 int32 len, bool clobber = false);
139 status_t AddHeaderField(uint32 encoding,
140 const char* field_name, const char* str,
141 bool clobber = false);
142 status_t AddHeaderField(const char* field_name,
143 const char* str, bool clobber = false);
145 status_t Send(bool sendNow = false,
146 bool removeAfterSending = false);
148 private:
149 int32 concatinate(char**, int32, char*);
150 int32 count_fields(char* name = NULL);
151 status_t find_field(char*, type_code*, char**, void**,
152 int32*, uint32*, char**, bool*, int32);
153 BList* find_field(const char*);
154 status_t get_field_name(char**, int32);
155 status_t set_field(const char*, type_code, const char*,
156 const void*, int32, uint32, const char*,
157 bool);
159 private:
160 BList* fFields;
161 bool fMultiPart;
164 #endif // _MAIL_H