From: helge Date: Fri, 29 Oct 2004 16:24:19 +0000 (+0000) Subject: minor fixes X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=60ff217559e6542b042da76b92d6f9826ade0a7b;p=sope minor fixes git-svn-id: http://svn.opengroupware.org/SOPE/trunk@325 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-mime/ChangeLog b/sope-mime/ChangeLog index 89d2eb4a..be44cf2c 100644 --- a/sope-mime/ChangeLog +++ b/sope-mime/ChangeLog @@ -1,3 +1,7 @@ +2004-10-29 Helge Hess + + * NGMime: minor cleanups (v4.3.195) + 2004-10-28 Helge Hess * NGImap4: added a constructor to NGImap4Envelope (v4.3.194) diff --git a/sope-mime/NGMail/ChangeLog b/sope-mime/NGMail/ChangeLog index f8ccafd7..710a3002 100644 --- a/sope-mime/NGMail/ChangeLog +++ b/sope-mime/NGMail/ChangeLog @@ -1,3 +1,9 @@ +2004-10-29 Helge Hess + + * NGSendMail.m: use fwrite() to write to pipe + + * NGMimeMessageGenerator.m: minor code cleanups + 2004-10-27 Marcus Mueller * NGMail.xcode: added NGSendMail.h diff --git a/sope-mime/NGMail/NGMimeMessageGenerator.h b/sope-mime/NGMail/NGMimeMessageGenerator.h index bfc72111..ea4e333b 100644 --- a/sope-mime/NGMail/NGMimeMessageGenerator.h +++ b/sope-mime/NGMail/NGMimeMessageGenerator.h @@ -1,7 +1,7 @@ /* Copyright (C) 2000-2004 SKYRIX Software AG - This file is part of OGo + This file is part of OpenGroupware.org. OGo is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the @@ -18,7 +18,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// $Id$ #ifndef __NGMime_NGMimeMessageGenerator_H__ #define __NGMime_NGMimeMessageGenerator_H__ diff --git a/sope-mime/NGMail/NGMimeMessageGenerator.m b/sope-mime/NGMail/NGMimeMessageGenerator.m index 6e61755f..ba65cbdc 100644 --- a/sope-mime/NGMail/NGMimeMessageGenerator.m +++ b/sope-mime/NGMail/NGMimeMessageGenerator.m @@ -18,7 +18,6 @@ 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" @@ -60,34 +59,33 @@ _base64Encoding(NGMimeBodyGenerator *self, 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"]; @@ -149,8 +147,8 @@ _base64Encoding(NGMimeBodyGenerator *self, 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); @@ -160,11 +158,11 @@ _base64Encoding(NGMimeBodyGenerator *self, 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); } } } @@ -172,49 +170,51 @@ _base64Encoding(NGMimeBodyGenerator *self, } -/* - content-transfer-encoding -*/ +/* content-transfer-encoding */ - (id)defaultBodyGenerator { - id gen; - - gen = [[NGMimeMessageBodyGenerator allocWithZone:[self zone]] init]; + NGMimeMessageBodyGenerator *gen; + + gen = [[NGMimeMessageBodyGenerator alloc] init]; [gen setUseMimeData:self->useMimeData]; return gen; } - (id)generatorForBodyOfPart:(id)_part { - id bodyGen = nil; - NGMimeType *contentType = nil; - NSString *type = nil; + id 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; } diff --git a/sope-mime/NGMail/NGSendMail.h b/sope-mime/NGMail/NGSendMail.h index e4b5fb25..55ca0e2e 100644 --- a/sope-mime/NGMail/NGSendMail.h +++ b/sope-mime/NGMail/NGSendMail.h @@ -19,8 +19,8 @@ 02111-1307, USA. */ -#ifndef __LSMail_NGSendMail_H__ -#define __LSMail_NGSendMail_H__ +#ifndef __NGMail_NGSendMail_H__ +#define __NGMail_NGSendMail_H__ #import #include @@ -64,4 +64,4 @@ @end -#endif /* __LSMail_NGSendMail_H__ */ +#endif /* __NGMail_NGSendMail_H__ */ diff --git a/sope-mime/NGMail/NGSendMail.m b/sope-mime/NGMail/NGSendMail.m index 2ab2102c..aba5465f 100644 --- a/sope-mime/NGMail/NGSendMail.m +++ b/sope-mime/NGMail/NGSendMail.m @@ -290,6 +290,7 @@ [fs release]; fs = nil; return NO; } + result = YES; NS_DURING { int read; @@ -301,19 +302,20 @@ 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 { @@ -334,8 +336,10 @@ 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]; diff --git a/sope-mime/NGMime/NGMimeFileData.h b/sope-mime/NGMime/NGMimeFileData.h index 1142314e..fbd61ca8 100644 --- a/sope-mime/NGMime/NGMimeFileData.h +++ b/sope-mime/NGMime/NGMimeFileData.h @@ -29,6 +29,8 @@ TODO: explain. Somehow this is an object to save loading an NSData to RAM. + Note: the -initWithBytes:length: method creates a temporary file! + Checked in: - NGMimeBodyGenerator - NGMimeBodyPart @@ -45,6 +47,7 @@ } - (id)initWithPath:(NSString *)_path removeFile:(BOOL)_remove; +- (id)initWithBytes:(const void *)_bytes length:(unsigned int)_length; /* operations */ diff --git a/sope-mime/Version b/sope-mime/Version index a1f50532..030b1c17 100644 --- a/sope-mime/Version +++ b/sope-mime/Version @@ -2,6 +2,6 @@ MAJOR_VERSION:=4 MINOR_VERSION:=3 -SUBMINOR_VERSION:=194 +SUBMINOR_VERSION:=195 # v4.2.149 requires libNGStreams v4.2.34