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 struct entry_ref; 18 19 /* -----------------------------------------------------------------------*/ 20 /* 'E-Mail' attributes...*/ 21 22 #define B_MAIL_ATTR_NAME "MAIL:name" /* indexed string*/ 23 #define B_MAIL_ATTR_STATUS "MAIL:status" /* indexed string*/ 24 #define B_MAIL_ATTR_PRIORITY "MAIL:priority" /* indexed string*/ 25 #define B_MAIL_ATTR_TO "MAIL:to" /* indexed string*/ 26 #define B_MAIL_ATTR_CC "MAIL:cc" /* indexed string*/ 27 #define B_MAIL_ATTR_FROM "MAIL:from" /* indexed string*/ 28 #define B_MAIL_ATTR_SUBJECT "MAIL:subject" /* indexed string*/ 29 #define B_MAIL_ATTR_REPLY "MAIL:reply" /* indexed string*/ 30 #define B_MAIL_ATTR_WHEN "MAIL:when" /* indexed time*/ 31 #define B_MAIL_ATTR_FLAGS "MAIL:flags" /* indexed int32*/ 32 #define B_MAIL_ATTR_RECIPIENTS "MAIL:recipients" /* string*/ 33 #define B_MAIL_ATTR_MIME "MAIL:mime" /* string*/ 34 #define B_MAIL_ATTR_HEADER "MAIL:header_length" /* int32*/ 35 #define B_MAIL_ATTR_CONTENT "MAIL:content_length" /* int32*/ 36 37 38 /* mail flags */ 39 enum mail_flags {B_MAIL_PENDING = 1, /* waiting to be sent*/ 40 B_MAIL_SENT = 2, /* has been sent*/ 41 B_MAIL_SAVE = 4}; /* save mail after sending*/ 42 43 #define B_MAIL_TYPE "text/x-email" /* mime type*/ 44 45 /* Everything past this point is deprecated. See MailMessage.h, mail_encoding.h 46 and MailDaemon.h for alternatives. */ 47 48 /* DEPRECATED -- DEPRECATED -- DEPRECATED -- DEPRECATED -- DEPRECATED */ 49 /* DEPRECATED -- DEPRECATED -- DEPRECATED -- DEPRECATED -- DEPRECATED */ 50 51 /* defines...*/ 52 53 /* schedule days */ 54 #define B_CHECK_NEVER 0 55 #define B_CHECK_WEEKDAYS 1 56 #define B_CHECK_DAILY 2 57 #define B_CHECK_CONTINUOUSLY 3 58 #define B_CHECK_CONTINUOSLY 3 59 60 /* max. lengths */ 61 #define B_MAX_USER_NAME_LENGTH 32 62 #define B_MAX_HOST_NAME_LENGTH 64 63 64 /* rfc822 header field types */ 65 #define B_MAIL_TO "To: " 66 #define B_MAIL_CC "Cc: " 67 #define B_MAIL_BCC "Bcc: " 68 #define B_MAIL_FROM "From: " 69 #define B_MAIL_DATE "Date: " 70 #define B_MAIL_REPLY "Reply-To: " 71 #define B_MAIL_SUBJECT "Subject: " 72 #define B_MAIL_PRIORITY "Priority: " 73 74 75 /* -----------------------------------------------------------------------*/ 76 /* structs...*/ 77 78 typedef struct { 79 char pop_name[B_MAX_USER_NAME_LENGTH]; 80 char pop_password[B_MAX_USER_NAME_LENGTH]; 81 char pop_host[B_MAX_HOST_NAME_LENGTH]; 82 char real_name[128]; 83 char reply_to[128]; 84 int32 days; /* see flags above*/ 85 int32 interval; /* in seconds*/ 86 int32 begin_time; /* in seconds*/ 87 int32 end_time; /* in seconds*/ 88 } mail_pop_account; 89 90 typedef struct { 91 bool alert; 92 bool beep; 93 } mail_notification; 94 95 /* -----------------------------------------------------------------------*/ 96 /* global functions...*/ 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 /* -----------------------------------------------------------------------*/ 117 /* class...*/ 118 119 class BMailMessage { 120 121 public: 122 BMailMessage(void); 123 ~BMailMessage(void); 124 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, bool clobber = false); 130 131 status_t AddEnclosure(entry_ref *ref, bool clobber = false); 132 status_t AddEnclosure(const char *path, bool clobber = false); 133 status_t AddEnclosure(const char *MIME_type, void *data, int32 len, 134 bool clobber = false); 135 136 status_t AddHeaderField(uint32 encoding, const char *field_name, const char *str, 137 bool clobber = false); 138 status_t AddHeaderField(const char *field_name, const char *str, 139 bool clobber = false); 140 141 status_t Send(bool send_now = false, 142 bool remove_when_I_have_completed_sending_this_message_to_your_preferred_SMTP_server = false); 143 144 145 /* -----------------------------------------------------------------------*/ 146 147 private: 148 BList* fFields; 149 bool fMultiPart; 150 151 int32 concatinate(char**, int32, char*); 152 int32 count_fields(char *name = NULL); 153 status_t find_field(char*, type_code*, char**, void**, int32*, 154 uint32*, char**, bool*, int32); 155 BList* find_field(const char*); 156 status_t get_field_name(char**, int32); 157 status_t set_field(const char*, type_code, const char*, const void*, 158 int32, uint32, const char*, bool); 159 }; 160 161 #endif /* _MAIL_H */ 162