Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
SMTP stuff. Don't get excited.
Browse files Browse the repository at this point in the history
  • Loading branch information
ccgus committed Sep 7, 2010
1 parent 6b42ad0 commit ad35821
Show file tree
Hide file tree
Showing 15 changed files with 581 additions and 215 deletions.
1 change: 1 addition & 0 deletions Letters.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions letterbox/LetterBox.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion letterbox/source/JRLog.m
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Expand Down
4 changes: 2 additions & 2 deletions letterbox/source/LBMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
@property (retain) NSString *flags;
@property (retain) LBMIMEMessage *mimePart;

- (void) parseHeaders;

- (void)parseHeaders;
- (NSData*)SMTPData;

@end
28 changes: 26 additions & 2 deletions letterbox/source/LBMessage.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "LBMessage.h"
#import "LetterBoxUtilities.h"
#import "LBMIMEParser.h"
#import "LBNSStringAdditions.h"

@implementation LBMessage

Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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
4 changes: 3 additions & 1 deletion letterbox/source/LBSMTPConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

}

- (void)test;
//- (void)test;
- (id)initWithAccount:(LBAccount*)account;

- (void)sendMessage:(LBMessage*)message block:(LBResponseBlock)block;

@end
22 changes: 14 additions & 8 deletions letterbox/source/LBSMTPConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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];
Expand All @@ -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) {

Expand Down Expand Up @@ -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];
Expand All @@ -176,7 +182,7 @@ - (void)sendMessage:(NSString*)message to:(NSString*)to from:(NSString*)from blo
}];
}


/*
- (void) test {
[self setDebugOutput:[LBPrefs boolForKey:@"debugIMAPMessages"]];
Expand Down Expand Up @@ -208,6 +214,6 @@ - (void) test {
}];
}];
}

*/

@end
3 changes: 3 additions & 0 deletions letterbox/source/LBTCPConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "LBTCPConnection.h"
#import "LBTCPReader.h"
#import "LBAccount.h"
#import "LetterBoxUtilities.h"

#import "TCP_Internal.h"
#import "IPAddress.h"
Expand Down Expand Up @@ -44,6 +45,8 @@ - (NSString*)modifyCommandString:(NSString*)commandString {

- (void)sendData:(NSData*)data readBlock:(void (^)(LBTCPReader *))block {

LBAssert(data);

bytesRead = 0;
self.responseBytes = [NSMutableData data];

Expand Down
8 changes: 7 additions & 1 deletion letterbox/source/LetterBoxUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
4 changes: 3 additions & 1 deletion letterbox/source/LetterBoxUtilities.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down
Loading

0 comments on commit ad35821

Please sign in to comment.