aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objc/rfc822/MCOMessageBuilder.h
blob: fbebb7f62974215a1e4fe75f1bad509dc9f037f1 (plain)
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
//
//  MCOMessageBuilder.h
//  mailcore2
//
//  Created by DINH Viêt Hoà on 3/22/13.
//  Copyright (c) 2013 MailCore. All rights reserved.
//

#ifndef MAILCORE_MCOMESSAGEBUILDER_H

#define MAILCORE_MCOMESSAGEBUILDER_H

#import <MailCore/MCOAbstractMessage.h>

/**
 This class will allow you to build a RFC 822 formatted message.
 For example when you need to send a message using SMTP,
 you need to generate first a RFC 822 formatted message.
 This class will help you do that.
 
    MCOMessageBuilder * builder = [[MCOMessageBuilder alloc] init];
    [[builder header] setFrom:[MCOAddress addressWithDisplayName:@"Hoa V. DINH" mailbox:@"hoa@etpan.org"];
    NSArray * to = [NSArray arrayWithObject:[MCOAddress addressWithDisplayName:@"Gael Roualland" mailbox:@"gael@etpan.org"]];
    [[builder header] setTo:to];
    [[builder header] setSubject:@"A nice picture!"];
    [builder setHTMLBody:@"<div>Here's the message I need to send.</div>"];
    [builder addAttachment:[MCOAttachment attachmentWithContentsOfFile:@"/Users/foo/Pictures/image.jpg"]];
    NSData * rfc822Data = [builder data];
 
*/

@class MCOAttachment;
@protocol MCOHTMLRendererDelegate;

@interface MCOMessageBuilder : MCOAbstractMessage <NSCopying>

/** Main HTML content of the message.*/
@property (nonatomic, copy, setter=setHTMLBody:) NSString * htmlBody;

/** Plain text content of the message.*/
@property (nonatomic, copy) NSString * textBody;

/** List of file attachments.*/
@property (nonatomic, copy) NSArray * /* MCOAttachment */ attachments;

/** List of related file attachments (included as cid: link in the HTML part).*/
@property (nonatomic, copy) NSArray * /* MCOAttachment */ relatedAttachments;

/** Prefix for the boundary identifier. Default value is nil.*/
@property (nonatomic, copy) NSString * boundaryPrefix;

/** Add an attachment.*/
- (void) addAttachment:(MCOAttachment *)attachment;

/** Add a related attachment.*/
- (void) addRelatedAttachment:(MCOAttachment *)attachment;

/** RFC 822 formatted message.*/
- (NSData *) data;

/** RFC 822 formatted message for encryption.*/
- (NSData *) dataForEncryption;

/** Store RFC 822 formatted message to file. */
- (BOOL) writeToFile:(NSString *)filename error:(NSError **)error;

/**
 Returns an OpenPGP signed message with a given signature.
 The signature needs to be computed on the data returned by -dataForEncryption
 before calling this method.
 You could use http://www.netpgp.com to generate it.
 */
- (NSData *) openPGPSignedMessageDataWithSignatureData:(NSData *)signature;

/**
 Returns an OpenPGP encrypted message with a given encrypted data.
 The encrypted data needs to be computed before calling this method.
 You could use http://www.netpgp.com to generate it.
 */
- (NSData *) openPGPEncryptedMessageDataWithEncryptedData:(NSData *)encryptedData;

/** HTML rendering of the message to be displayed in a web view. The delegate can be nil.*/
- (NSString *) htmlRenderingWithDelegate:(id <MCOHTMLRendererDelegate>)delegate;

/** HTML rendering of the body of the message to be displayed in a web view.*/
- (NSString *) htmlBodyRendering;

/** Text rendering of the message.*/
- (NSString *) plainTextRendering;

/** Text rendering of the body of the message. All end of line will be removed and white spaces cleaned up.
 This method can be used to generate the summary of the message.*/
- (NSString *) plainTextBodyRendering;

/** Text rendering of the body of the message. All end of line will be removed and white spaces cleaned up if requested.
 This method can be used to generate the summary of the message.*/
- (NSString *) plainTextBodyRenderingAndStripWhitespace:(BOOL)stripWhitespace;

@end

#endif