Skip to content
This repository
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 362 lines (292 sloc) 9.71 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
/*
* MailCore
*
* Copyright (C) 2007 - Matt Ronge
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the MailCore project nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/

#import <Foundation/Foundation.h>
#import <libetpan/libetpan.h>

/**
CTCoreMessage is how you work with messages. The easiest way to instantiate a CTCoreMessage
is to first setup a CTCoreAccount object and then get a CTCoreFolder object and then use it's
convenience method messageWithUID: to get a message object you can work with.

Anything that begins with "fetch", requires that an active network connection is present.
*/

@class CTCoreFolder, CTCoreAddress, CTCoreAttachment, CTMIME;

typedef enum {
    CTCoreMessageUrgentPriority = 1,
    CTCoreMessageNormalPriority = 2,
    CTCoreMessageNonUrgentPriority
} CTCoreMessagePriority;


@interface CTCoreMessage : NSObject {
    struct mailmessage *myMessage;
    struct mailimf_single_fields *myFields;
    CTMIME *myParsedMIME;
    NSUInteger mySequenceNumber;
    NSError *lastError;
    CTCoreFolder *parentFolder;
    CTCoreMessagePriority mailPriority;
}
/**
If an error occurred (nil or return of NO) call this method to get the error
*/
@property (nonatomic, retain) NSError *lastError;

@property (nonatomic, retain) CTCoreFolder *parentFolder;

/**
If the body structure has been fetched, this will contain the MIME structure
*/
@property(retain) CTMIME *mime;

/**
Used to instantiate an empty message object.
*/
- (id)init;

/**
Used to instantiate a message object with the contents of a mailmessage struct
(a LibEtPan type). The mailmessage struct does not include any body information,
so after calling this method the message will have a body which is NULL.
*/
- (id)initWithMessageStruct:(struct mailmessage *)message;

/**
Used to instantiate a message object based off the contents of a file on disk.
The file on disk must be a valid MIME message.
*/
- (id)initWithFileAtPath:(NSString *)path;

/**
Used to instantiate a message object based off a string
that contains a valid MIME message
*/
- (id)initWithString:(NSString *)msgData;

/**
If a method returns nil or in the case of a BOOL returns NO, call this to get the error that occured
*/
- (NSError *)lastError;

/**
Returns YES if this message body structure has been downloaded, and NO otherwise.
*/
- (BOOL)hasBodyStructure;

/**
If the messages body structure hasn't been downloaded already it will be fetched from the server.

The body structure is needed to get attachments or the message body
@return Return YES on success, NO on error. Call method lastError to get error if one occurred
*/
- (BOOL)fetchBodyStructure;

/**
This method returns the parsed plain text message body as an NSString.

If a plaintext body isn't found an empty string is returned
*/
- (NSString *)body;

/**
This method returns the html body as an NSString.
*/
- (NSString *)htmlBody;

/**
Returns a message body as an NSString.

@param isHTML Pass in a BOOL pointer that will be set to YES if an HTML body is loaded

First attempts to retrieve a plain text body, if that fails then
tries for an HTML body.
*/
- (NSString *)bodyPreferringPlainText:(BOOL *)isHTML;

/**
This method sets the message body. Plaintext only please!
*/
- (void)setBody:(NSString *)body;

/**
Use this method to set the body if you have HTML content.
*/
- (void)setHTMLBody:(NSString *)body;

/**
A list of attachments this message has
*/
- (NSArray *)attachments;

/**
Add an attachment to the message.
Only used when sending e-mail
*/
- (void)addAttachment:(CTCoreAttachment *)attachment;

/**
Returns the subject of the message.
*/
- (NSString *)subject;

/**
Will set the subject of the message, use this when composing e-mail.
*/
- (void)setSubject:(NSString *)subject;

/**
Returns the date as given in the Date mail field
*/
- (NSDate *)senderDate;

/**
Returns YES if the message is deleted.
*/
- (BOOL)isDeleted;

/**
Returns YES if the message is unread.
*/
- (BOOL)isUnread;

/**
Returns YES if the message is recent and unread.
*/
- (BOOL)isNew;

/**
Returns YES if the message is starred (flagged in IMAP terms).
*/
- (BOOL)isStarred;

/**
A machine readable ID that is guaranteed unique by the
host that generated the message
*/
- (NSString *)messageId;

/**
Returns an NSUInteger containing the messages UID. This number is unique across sessions
*/
- (NSUInteger)uid;

/**
Returns the message sequence number, this number cannot be used across sessions
*/
- (NSUInteger)sequenceNumber;

/**
Returns the message size in bytes
*/
- (NSUInteger)messageSize;

/**
Returns the message flags.
The flags contain if there user has replied, forwarded, read, delete etc.
See MailCoreTypes.h for a list of constants
*/
- (NSUInteger)flags;

/**
Returns the message extionsion flags.
The extension flags contain flags other than standard flags in flags property. This include "Draft" flag.
See MailCoreTypes.h for a list of constants
*/
- (NSArray *)extionsionFlags;

/**
Set the message sequence number.
This will NOT set any thing on the server.
This is used to assign sequence numbers after retrieving the message list.
*/
- (void)setSequenceNumber:(NSUInteger)sequenceNumber;

/**
Parses the from list, the result is an NSSet containing CTCoreAddress's
*/
- (NSSet *)from;

/**
Sets the message's from addresses
@param addresses A NSSet containing CTCoreAddress's
*/
- (void)setFrom:(NSSet *)addresses;

/**
Returns the sender.
The sender which isn't always the actual person who sent the message, it's usually the
address of the machine that sent the message. In reality, this method isn't very useful, use from: instead.
*/
- (CTCoreAddress *)sender;

/**
Returns the list of people the message was sent to, returns an NSSet containing CTAddress's.
*/
- (NSSet *)to;

/**
Sets the message's to addresses
@param addresses A NSSet containing CTCoreAddress's
*/
- (void)setTo:(NSSet *)addresses;

/**
Return the list of messageIds from the in-reply-to field
*/
- (NSArray *)inReplyTo;

/**
Sets the message's in-reply-to messageIds
@param messageIds A NSArray containing NSString messageId's
*/
- (void)setInReplyTo:(NSArray *)messageIds;

/**
Return the list of messageIds from the references field
*/
- (NSArray *)references;

/**
Sets the message's references
@param messageIds A NSArray containing NSString messageId's
*/
- (void)setReferences:(NSArray *)messageIds;

/**
Returns the list of people the message was cced to, returns an NSSet containing CTAddress's.
*/
- (NSSet *)cc;

/**
Sets the message's cc addresses
@param addresses A NSSet containing CTCoreAddress's
*/
- (void)setCc:(NSSet *)addresses;

/**
Returns the list of people the message was bcced to, returns an NSSet containing CTAddress's.
*/
- (NSSet *)bcc;

/**
Sets the message's bcc addresses
@param addresses A NSSet containing CTCoreAddress's
*/
- (void)setBcc:(NSSet *)addresses;

/**
Returns the list of people the message was in reply-to, returns an NSSet containing CTAddress's.
*/
- (NSSet *)replyTo;

/**
Sets the message's reply to addresses
@param addresses A NSSet containing CTCoreAddress's
*/
- (void)setReplyTo:(NSSet *)addresses;

/**
Returns the message rendered as the appropriate MIME and IMF content.
Use this only if you want the raw encoding of the message.
*/
- (NSString *)render;

/**
Returns the message in the format Mail.app uses, Emlx.
This format stores the message headers, body, and flags.
*/
- (NSData *)messageAsEmlx;

/**
Fetches from the server the rfc822 content of the message, which are the headers and the message body.
@return Return nil on error. Call method lastError to get error if one occurred
*/
- (NSString *)rfc822;

/**
Fetches from the server the rfc822 content of the message headers.
@return Return nil on error. Call method lastError to get error if one occurred
*/
- (NSString *)rfc822Header;


/**
Sets the outgoing message's priority header value.
Support for Mail Prioirty header defined in IMAP 4021 and X-Prioirty header.
*/
- (void)setMailPriority:(CTCoreMessagePriority)priority;

/* Intended for advanced use only */
- (struct mailmessage *)messageStruct;
- (mailimap *)imapSession;
- (void)setBodyStructure:(struct mailmime *)mime;
- (void)setFields:(struct mailimf_fields *)fields;
@end
Something went wrong with that request. Please try again.