2 Copyright (C) 2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include "NGImap4Envelope.h"
23 #include "NGImap4EnvelopeAddress.h"
26 @implementation NGImap4Envelope
28 - (id)newEnvelopeAddressForEMail:(id)_email {
29 if (![_email isNotNull])
32 if ([_email isKindOfClass:[NGImap4EnvelopeAddress class]])
35 _email = [_email stringValue];
36 if ([_email length] == 0)
38 return [[NGImap4EnvelopeAddress alloc] initWithString:_email];
40 - (NSArray *)envelopeAddressesForEMails:(NSArray *)_emails {
46 if ((count = [_emails count]) == 0)
47 return [NSArray array];
49 ma = [NSMutableArray arrayWithCapacity:count];
50 for (i = 0; i < count; i++) {
51 NGImap4EnvelopeAddress *envaddr;
53 envaddr = [self newEnvelopeAddressForEMail:[_emails objectAtIndex:i]];
54 if (![envaddr isNotNull])
57 [ma addObject:envaddr];
63 - (id)initWithMessageID:(NSString *)_msgID subject:(NSString *)_subject
64 sender:(id)_sender replyTo:(id)_replyTo
65 to:(NSArray *)_to cc:(NSArray *)_cc bcc:(NSArray *)_bcc
67 if ((self = [self init])) {
68 self->msgId = [_msgID copy];
69 self->subject = [_subject copy];
71 self->from = [self newEnvelopeAddressForEMail:_sender];
72 self->replyTo = [self newEnvelopeAddressForEMail:_replyTo];
74 self->to = [[self envelopeAddressesForEMails:_to] copy];
75 self->cc = [[self envelopeAddressesForEMails:_cc] copy];
76 self->bcc = [[self envelopeAddressesForEMails:_bcc] copy];
83 [self->subject release];
84 [self->inReplyTo release];
85 [self->msgId release];
87 [self->sender release];
88 [self->replyTo release];
97 - (NSCalendarDate *)date {
101 return self->subject;
103 - (NSString *)inReplyTo {
104 return self->inReplyTo;
106 - (NSString *)messageID {
109 - (NGImap4EnvelopeAddress *)from {
112 - (NGImap4EnvelopeAddress *)sender {
115 - (NGImap4EnvelopeAddress *)replyTo {
116 return self->replyTo;
128 /* derived accessors */
131 return [self->to count] > 0 ? YES : NO;
134 return [self->cc count] > 0 ? YES : NO;
137 return [self->bcc count] > 0 ? YES : NO;
142 - (NSString *)description {
145 ms = [NSMutableString stringWithCapacity:128];
146 [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])];
148 if (self->date) [ms appendFormat:@" date='%@'", self->date];
149 if (self->subject) [ms appendFormat:@" subject='%@'", self->subject];
150 if (self->msgId) [ms appendFormat:@" msgid='%@'", self->msgId];
151 if (self->inReplyTo) [ms appendFormat:@" inreplyto='%@'", self->inReplyTo];
153 if (self->from) [ms appendFormat:@" from=%@", [self->from email]];
154 if (self->sender) [ms appendFormat:@" sender=%@", [self->sender email]];
156 if (self->to) [ms appendFormat:@" to=%@", self->to];
157 if (self->cc) [ms appendFormat:@" cc=%@", self->cc];
158 if (self->bcc) [ms appendFormat:@" bcc=%@", self->bcc];
160 [ms appendString:@">"];
164 @end /* NGImap4Envelope */