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 45 /* -----------------------------------------------------------------------*/ 46 /* defines...*/ 47 48 /* schedule days */ 49 #define B_CHECK_NEVER 0 50 #define B_CHECK_WEEKDAYS 1 51 #define B_CHECK_DAILY 2 52 #define B_CHECK_CONTINUOUSLY 3 53 #define B_CHECK_CONTINUOSLY 3 54 55 /* max. lengths */ 56 #define B_MAX_USER_NAME_LENGTH 32 57 #define B_MAX_HOST_NAME_LENGTH 64 58 59 /* rfc822 header field types */ 60 #define B_MAIL_TO "To: " 61 #define B_MAIL_CC "Cc: " 62 #define B_MAIL_BCC "Bcc: " 63 #define B_MAIL_FROM "From: " 64 #define B_MAIL_DATE "Date: " 65 #define B_MAIL_REPLY "Reply-To: " 66 #define B_MAIL_SUBJECT "Subject: " 67 #define B_MAIL_PRIORITY "Priority: " 68 69 70 /* -----------------------------------------------------------------------*/ 71 /* structs...*/ 72 73 typedef struct { 74 char pop_name[B_MAX_USER_NAME_LENGTH]; 75 char pop_password[B_MAX_USER_NAME_LENGTH]; 76 char pop_host[B_MAX_HOST_NAME_LENGTH]; 77 char real_name[128]; 78 char reply_to[128]; 79 int32 days; /* see flags above*/ 80 int32 interval; /* in seconds*/ 81 int32 begin_time; /* in seconds*/ 82 int32 end_time; /* in seconds*/ 83 } mail_pop_account; 84 85 typedef struct { 86 bool alert; 87 bool beep; 88 } mail_notification; 89 90 91 /* -----------------------------------------------------------------------*/ 92 /* global functions...*/ 93 94 _IMPEXP_MAIL int32 count_pop_accounts(void); 95 _IMPEXP_MAIL status_t get_pop_account(mail_pop_account*, int32 index = 0); 96 _IMPEXP_MAIL status_t set_pop_account(mail_pop_account*, int32 index = 0, 97 bool save = true); 98 _IMPEXP_MAIL status_t get_smtp_host(char*); 99 _IMPEXP_MAIL status_t set_smtp_host(char*, bool save = true); 100 _IMPEXP_MAIL status_t get_mail_notification(mail_notification*); 101 _IMPEXP_MAIL status_t set_mail_notification(mail_notification*, bool save = true); 102 103 _IMPEXP_MAIL status_t check_for_mail(int32 *incoming_count = NULL); 104 _IMPEXP_MAIL status_t send_queued_mail(void); 105 _IMPEXP_MAIL status_t forward_mail(entry_ref*, const char* recipients, bool now = true); 106 107 _IMPEXP_MAIL ssize_t decode_base64(char *out, char *in, off_t length, 108 bool replace_cr = false); 109 _IMPEXP_MAIL ssize_t encode_base64(char *out, char *in, off_t length); 110 111 112 /* -----------------------------------------------------------------------*/ 113 /* class...*/ 114 115 class BMailMessage { 116 117 public: 118 BMailMessage(void); 119 ~BMailMessage(void); 120 121 status_t AddContent(const char *text, int32 length, 122 uint32 encoding = B_ISO1_CONVERSION, 123 bool clobber = false); 124 status_t AddContent(const char *text, int32 length, 125 const char *encoding, bool clobber = false); 126 127 status_t AddEnclosure(entry_ref *ref, bool clobber = false); 128 status_t AddEnclosure(const char *path, bool clobber = false); 129 status_t AddEnclosure(const char *MIME_type, void *data, int32 len, 130 bool clobber = false); 131 132 status_t AddHeaderField(uint32 encoding, const char *field_name, const char *str, 133 bool clobber = false); 134 status_t AddHeaderField(const char *field_name, const char *str, 135 bool clobber = false); 136 137 status_t Send(bool send_now = false, 138 bool remove_when_I_have_completed_sending_this_message_to_your_preferred_SMTP_server = false); 139 140 141 /* -----------------------------------------------------------------------*/ 142 143 private: 144 BList* fFields; 145 bool fMultiPart; 146 147 int32 concatinate(char**, int32, char*); 148 int32 count_fields(char *name = NULL); 149 status_t find_field(char*, type_code*, char**, void**, int32*, 150 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*, const void*, 154 int32, uint32, const char*, bool); 155 }; 156 157 #endif /* _MAIL_H */ 158