Permalink
Browse files

SMTP stuff. Don't get excited.

  • Loading branch information...
ccgus committed Sep 7, 2010
1 parent 6b42ad0 commit ad35821c571eaaf7c310e88e8a6f67b49a481011
@@ -521,6 +521,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
+ CC = /opt/bin/clang;
COPY_PHASE_STRIP = NO;
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
GCC_DYNAMIC_NO_PIC = NO;
@@ -1177,6 +1177,7 @@
1DEB91AE08733DA50010E9CD /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CC = /opt/bin/clang;
COPY_PHASE_STRIP = NO;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
View
@@ -229,7 +229,7 @@ BOOL IsJRLogLevelActive(id self_, JRLogLevel callerLevel_) {
//
va_list args;
va_start(args, format_);
- NSString *message = [[NSString alloc] initWithFormat:format_ arguments:args];
+ NSString *message = [[[NSString alloc] initWithFormat:format_ arguments:args] autorelease];
va_end(args);
[[JRLogOutput sharedOutput] logWithLevel:callerLevel_
@@ -37,7 +37,7 @@
@property (retain) NSString *flags;
@property (retain) LBMIMEMessage *mimePart;
-- (void) parseHeaders;
-
+- (void)parseHeaders;
+- (NSData*)SMTPData;
@end
@@ -9,6 +9,7 @@
#import "LBMessage.h"
#import "LetterBoxUtilities.h"
#import "LBMIMEParser.h"
+#import "LBNSStringAdditions.h"
@implementation LBMessage
@@ -84,12 +85,12 @@ - (id)copyWithZone:(NSZone*)zone {
return m;
}
-- (id) copy {
+- (id)copy {
return [self copyWithZone:nil];
}
-- (void) parseHeaders {
+- (void)parseHeaders {
if (!subject) {
self.subject = [messageURL lastPathComponent];
@@ -159,4 +160,27 @@ - (NSString*)messageBody {
return messageBody;
}
+- (NSData*)SMTPData {
+
+ NSMutableString *ret = [NSMutableString string];
+
+ if (to) {
+ [ret appendFormat:@"To: %@\r\n", to];
+ }
+
+ if (sender) {
+ [ret appendFormat:@"From: %@\r\n", sender];
+ }
+
+ if (subject) {
+ [ret appendFormat:@"Subject: %@\r\n", subject];
+ }
+
+ [ret appendFormat:@"%@\r\n.\r\n", messageBody];
+
+ debug(@"ret: '%@'", ret);
+
+ return [ret utf8Data];
+}
+
@end
@@ -8,7 +8,9 @@
}
-- (void)test;
+//- (void)test;
- (id)initWithAccount:(LBAccount*)account;
+- (void)sendMessage:(LBMessage*)message block:(LBResponseBlock)block;
+
@end
@@ -3,8 +3,10 @@
#import "LBAccount.h"
#import "IPAddress.h"
#import "LetterBoxUtilities.h"
+#import "LBMessage.h"
static NSString *LBSMTPHELLO = @"HELO";
+static NSString *LBSMTPEHLO = @"EHLO";
static NSString *LBSMTPMAILFROM = @"MAIL FROM:";
static NSString *LBSMTPRCPTTO = @"RCPT TO:";
static NSString *LBSMTPDATA = @"DATA";
@@ -70,6 +72,8 @@ - (void)connectUsingBlock:(LBResponseBlock)block {
NSString *serverName = [[self address] hostname];
+ // FIXME: we should really use esmtp here, and find out the server capibilities and such.
+ //[self sendCommand:LBSMTPEHLO withArgument:serverName readBlock:^(LBTCPReader *arg1) {
[self sendCommand:LBSMTPHELLO withArgument:serverName readBlock:^(LBTCPReader *arg1) {
[self appendDataFromReader:reader];
@@ -95,12 +99,16 @@ - (void)connectUsingBlock:(LBResponseBlock)block {
[super connectUsingBlock:block];
}
-- (void)sendMessage:(NSString*)message to:(NSString*)to from:(NSString*)from block:(LBResponseBlock)block {
+- (void)sendMessage:(LBMessage*)message block:(LBResponseBlock)block {
+
+ LBAssert([message to]);
+ LBAssert([message sender]);
+ LBAssert([message messageBody]);
responseBlock = [block copy];
- to = [NSString stringWithFormat:@"%@<%@>", LBSMTPRCPTTO, to];
- from = [NSString stringWithFormat:@"%@<%@>", LBSMTPMAILFROM, from];
+ NSString *to = [NSString stringWithFormat:@"%@<%@>", LBSMTPRCPTTO, [message to]];
+ NSString *from = [NSString stringWithFormat:@"%@<%@>", LBSMTPMAILFROM, [message sender]];
[self sendCommand:from withArgument:nil readBlock:^(LBTCPReader *reader) {
@@ -153,9 +161,7 @@ - (void)sendMessage:(NSString*)message to:(NSString*)to from:(NSString*)from blo
return;
}
- NSString *fixedmessage = [message stringByAppendingString:@"\r\n.\r\n"];
-
- [self sendData:[fixedmessage dataUsingEncoding:NSUTF8StringEncoding] readBlock:^(LBTCPReader *reader) {
+ [self sendData:[message SMTPData] readBlock:^(LBTCPReader *reader) {
[self appendDataFromReader:reader];
NSString *res = [[self responseBytes] lbFirstLine];
@@ -176,7 +182,7 @@ - (void)sendMessage:(NSString*)message to:(NSString*)to from:(NSString*)from blo
}];
}
-
+/*
- (void) test {
[self setDebugOutput:[LBPrefs boolForKey:@"debugIMAPMessages"]];
@@ -208,6 +214,6 @@ - (void) test {
}];
}];
}
-
+*/
@end
@@ -9,6 +9,7 @@
#import "LBTCPConnection.h"
#import "LBTCPReader.h"
#import "LBAccount.h"
+#import "LetterBoxUtilities.h"
#import "TCP_Internal.h"
#import "IPAddress.h"
@@ -44,6 +45,8 @@ - (NSString*)modifyCommandString:(NSString*)commandString {
- (void)sendData:(NSData*)data readBlock:(void (^)(LBTCPReader *))block {
+ LBAssert(data);
+
bytesRead = 0;
self.responseBytes = [NSMutableData data];
@@ -31,7 +31,7 @@
#import <Foundation/Foundation.h>
-void LBQuickError(NSError **err, NSString *domain, NSInteger code, NSString *description);
+BOOL LBQuickError(NSError **err, NSString *domain, NSInteger code, NSString *description);
NSString *LBQuote(NSString *body, NSString *prefix);
@@ -44,3 +44,9 @@ NSDictionary* LBParseSimpleFetchResponse(NSString *fetchResponse);
#define LBRelease(a) { [a release]; a = nil; }
#define LBPrefs [NSUserDefaults standardUserDefaults]
+
+#ifdef DEBUG
+ #define LBAssert(...) assert(__VA_ARGS__)
+#else
+ #define LBAssert(...)
+#endif
@@ -57,12 +57,14 @@ void letterbox_logger(int direction, const char * str, size_t size) {
}
-void LBQuickError(NSError **err, NSString *domain, NSInteger code, NSString *description) {
+BOOL LBQuickError(NSError **err, NSString *domain, NSInteger code, NSString *description) {
// fixme: add a com.lettersapp in front of the domain?
if (err) {
*err = [NSError errorWithDomain:domain code:code userInfo:[NSDictionary dictionaryWithObject:description forKey:NSLocalizedDescriptionKey]];
}
+ // make the static analyzer shudup by returning a BOOL
+ return YES;
}
Oops, something went wrong.

0 comments on commit ad35821

Please sign in to comment.