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 7 8 9 #include <UTF8.h> 10 11 12 class BList; 13 struct entry_ref; 14 15 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_FROM "MAIL:from" // indexed string 23 #define B_MAIL_ATTR_SUBJECT "MAIL:subject" // indexed string 24 #define B_MAIL_ATTR_REPLY "MAIL:reply" // indexed string 25 #define B_MAIL_ATTR_WHEN "MAIL:when" // indexed time 26 #define B_MAIL_ATTR_FLAGS "MAIL:flags" // indexed int32 27 #define B_MAIL_ATTR_RECIPIENTS "MAIL:recipients" // string 28 #define B_MAIL_ATTR_MIME "MAIL:mime" // string 29 #define B_MAIL_ATTR_HEADER "MAIL:header_length" // int32 30 #define B_MAIL_ATTR_CONTENT "MAIL:content_length" // int32 31 32 33 // mail flags 34 enum mail_flags { 35 B_MAIL_PENDING = 1, // waiting to be sent 36 37 B_MAIL_SENT = 2, // has been sent 38 39 B_MAIL_SAVE = 4 // save mail after 40 // sending 41 }; 42 43 #define B_MAIL_TYPE "text/x-email" // mime type 44 45 46 // WARNING: Everything past this point is deprecated. See MailMessage.h, 47 // mail_encoding.h and MailDaemon.h for alternatives. 48 49 50 // #pragma mark - 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 // #pragma mark - structs 75 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 // #pragma mark - global functions 96 97 98 int32 count_pop_accounts(void); 99 status_t get_pop_account(mail_pop_account*, int32 index = 0); 100 status_t set_pop_account(mail_pop_account*, int32 index = 0, 101 bool save = true); 102 status_t get_smtp_host(char*); 103 status_t set_smtp_host(char*, bool save = true); 104 status_t get_mail_notification(mail_notification*); 105 status_t set_mail_notification(mail_notification*, bool save = true); 106 107 status_t check_for_mail(int32* incoming_count = NULL); 108 status_t send_queued_mail(void); 109 status_t forward_mail(entry_ref*, const char* recipients, bool now = true); 110 111 ssize_t decode_base64(char* out, char* in, off_t length, 112 bool replace_cr = false); 113 ssize_t encode_base64(char* out, char* in, off_t length); 114 115 116 // #pragma mark - BMailMessage 117 118 class BMailMessage { 119 public: 120 BMailMessage(); 121 ~BMailMessage(); 122 123 status_t AddContent(const char* text, int32 length, 124 uint32 encoding = B_ISO1_CONVERSION, 125 bool clobber = false); 126 status_t AddContent(const char* text, int32 length, 127 const char* encoding, 128 bool clobber = false); 129 130 status_t AddEnclosure(entry_ref* ref, 131 bool clobber = false); 132 status_t AddEnclosure(const char* path, 133 bool clobber = false); 134 status_t AddEnclosure(const char* MIME_type, void* data, 135 int32 len, bool clobber = false); 136 137 status_t AddHeaderField(uint32 encoding, 138 const char* field_name, const char* str, 139 bool clobber = false); 140 status_t AddHeaderField(const char* field_name, 141 const char* str, bool clobber = false); 142 143 status_t Send(bool sendNow = false, 144 bool removeAfterSending = false); 145 146 private: 147 int32 concatinate(char**, int32, char*); 148 int32 count_fields(char* name = NULL); 149 status_t find_field(char*, type_code*, char**, void**, 150 int32*, uint32*, char**, bool*, int32); 151 BList* find_field(const char*); 152 status_t get_field_name(char**, int32); 153 status_t set_field(const char*, type_code, const char*, 154 const void*, int32, uint32, const char*, 155 bool); 156 157 private: 158 BList* fFields; 159 bool fMultiPart; 160 }; 161 162 #endif // _MAIL_H 163