Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
*/
-// $Id: NGMimeMessageGenerator.m 11 2004-08-20 19:20:03Z helge $
#include "NGMimeMessageGenerator.h"
#include "NGMimeMessage.h"
type = [_part contentType];
if ([[type type] isEqualToString:@"text"] == YES) {
+ NSUserDefaults *ud;
BOOL use8bit;
- use8bit = [[NSUserDefaults standardUserDefaults]
- boolForKey:
- @"Mail_Use_8bit_Encoding_For_Text"];
-
- if (use8bit) {
+ ud = [NSUserDefaults standardUserDefaults];
+ use8bit = [ud boolForKey:@"Mail_Use_8bit_Encoding_For_Text"];
+
+ if (use8bit)
transEnc = @"8bit";
- }
else {
_data_ = [_data_ dataByEncodingQuotedPrintable];
transEnc = @"quoted-printable";
}
}
else {
+ NGMimeType *appOctet;
+
_data_ = [_data_ dataByEncodingBase64];
transEnc = @"base64";
- if (type == nil) {
- [_addHeaders setObject:[NGMimeType mimeType:@"application"
- subType:@"octet-stream"]
- forKey:@"content-type"];
- }
+ appOctet = [NGMimeType mimeType:@"application" subType:@"octet-stream"];
+ if (type == nil)
+ [_addHeaders setObject:appOctet forKey:@"content-type"];
}
}
- else { // no encoding
+ else /* no encoding */
transEnc = @"7bit";
- }
+
[_addHeaders setObject:transEnc forKey:@"content-transfer-encoding"];
[_addHeaders setObject:[NSNumber numberWithInt:[_data_ length]]
forKey:@"content-length"];
unsigned isoEndLen = 2;
desLen = length * 3 + 20;
-
- des = NGMallocAtomic(sizeof(char) * desLen + 2);
+
+ des = calloc(desLen + 2, sizeof(char));
// memcpy(des, bytes, cnt);
memcpy(des, iso, isoLen);
memcpy(des + isoLen + desLen, isoEnd, isoEndLen);
data = [NSData dataWithBytesNoCopy:des
- length:(isoLen + desLen + isoEndLen)];
+ length:(isoLen + desLen + isoEndLen)];
}
else {
NSLog(@"WARNING: An error occour during quoted-printable decoding");
- if (des) NGFree(des);
+ if (des != NULL) free(des);
}
}
}
}
-/*
- content-transfer-encoding
-*/
+/* content-transfer-encoding */
- (id<NGMimeBodyGenerator>)defaultBodyGenerator {
- id gen;
-
- gen = [[NGMimeMessageBodyGenerator allocWithZone:[self zone]] init];
+ NGMimeMessageBodyGenerator *gen;
+
+ gen = [[NGMimeMessageBodyGenerator alloc] init];
[gen setUseMimeData:self->useMimeData];
return gen;
}
- (id<NGMimeBodyGenerator>)generatorForBodyOfPart:(id<NGMimePart>)_part {
- id<NGMimeBodyGenerator> bodyGen = nil;
- NGMimeType *contentType = nil;
- NSString *type = nil;
+ id<NGMimeBodyGenerator> bodyGen;
+ NGMimeType *contentType;
+ NSString *type;
+ Class generatorClass;
- if (self->delegateRespondsTo.generatorGeneratorForBodyOfPart)
+ if (self->delegateRespondsTo.generatorGeneratorForBodyOfPart) {
bodyGen = [self->delegate mimePartGenerator:self
generatorForBodyOfPart:self->part];
-
- if (bodyGen)
- return bodyGen;
-
- contentType = [_part contentType];
- if (contentType == nil) {
- contentType = [self defaultContentTypeForPart:_part];
+
+ if (bodyGen != nil)
+ return bodyGen;
}
+
+ if ((contentType = [_part contentType]) == nil)
+ contentType = [self defaultContentTypeForPart:_part];
+
if (contentType == nil) {
- NSLog(@"WARNING: no content-type");
+ NSLog(@"WARNING(%s): missing content-type in part 0x%08X.", _part);
return nil;
}
+
type = [contentType type];
- if ([type isEqualToString:NGMimeTypeMultipart]) {
- bodyGen = [[[NGMimeMessageMultipartBodyGenerator alloc] init] autorelease];
- }
- else if ([type isEqualToString:NGMimeTypeText]) {
- bodyGen = [[[NGMimeMessageTextBodyGenerator alloc] init] autorelease];
- }
+
+ generatorClass = Nil;
+ if ([type isEqualToString:NGMimeTypeMultipart])
+ generatorClass = [NGMimeMessageMultipartBodyGenerator class];
+ else if ([type isEqualToString:NGMimeTypeText])
+ generatorClass = [NGMimeMessageTextBodyGenerator class];
else if (([type isEqualToString:NGMimeTypeMessage]) &&
[[contentType subType] isEqualToString:@"rfc822"]) {
- bodyGen = [[[NGMimeMessageRfc822BodyGenerator alloc] init] autorelease];
+ generatorClass = [NGMimeMessageRfc822BodyGenerator class];
}
+
+ bodyGen = [[[generatorClass alloc] init] autorelease];
[(id)bodyGen setUseMimeData:self->useMimeData];
return bodyGen;
}
[fs release]; fs = nil;
return NO;
}
+
result = YES;
NS_DURING {
int read;
read = (bufCnt > (fileLen - alreadyRead))
? fileLen - alreadyRead : bufCnt;
-
- while ((read = [fs readBytes:buffer count:read])) {
- alreadyRead += read;
-
- buffer[read] = '\0';
-
- if (fputs(buffer, _fd) == EOF) {
+
+ while ((read = [fs readBytes:buffer count:read]) != 0) {
+ int rc;
+
+ alreadyRead += read;
+
+ rc = fwrite(buffer, read, 1, _fd);
+ if (rc == 0) {
fprintf(stderr, "%s: Failed to write %i bytes to process\n",
__PRETTY_FUNCTION__, alreadyRead);
break;
- }
- if (alreadyRead == fileLen)
- break;
+ }
+ if (alreadyRead == fileLen)
+ break;
}
}
NS_HANDLER {
written = fwrite((char *)[_data bytes], [_data length],
1, _fd);
- if (written > 0)
+ if (written > 0) {
+ [self logWithFormat:@"wrote %d, length %d", written, [_data length]];
return YES;
+ }
[self logWithFormat:@"[2] Could not write mail to sendmail <%d>", errno];