Skip to content

Commit

Permalink
Cleaned the code and fixed #2894 while at it ...
Browse files Browse the repository at this point in the history
  • Loading branch information
extrafu committed Sep 17, 2014
1 parent a4ab294 commit 11adf38
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 50 deletions.
1 change: 1 addition & 0 deletions SoObjects/Appointments/SOGoAppointmentFolder.m
Expand Up @@ -2369,6 +2369,7 @@ - (SOGoWebDAVValue *) davCalendarComponentSet
valueForObject: @"<n1:comp name=\"VEVENT\"/>"
attributes: nil]];

// See bugs #2878 and #2879
[components addObject: [SOGoWebDAVValue
valueForObject: @"<n1:comp name=\"VFREEBUSY\"/>"
attributes: nil]];
Expand Down
99 changes: 50 additions & 49 deletions SoObjects/Mailer/SOGoDraftObject.m
Expand Up @@ -45,6 +45,7 @@
#import <NGImap4/NGImap4Client.h>
#import <NGImap4/NGImap4Envelope.h>
#import <NGImap4/NGImap4EnvelopeAddress.h>
#import <NGMail/NGMailAddress.h>
#import <NGMail/NGMailAddressParser.h>
#import <NGMail/NGMimeMessage.h>
#import <NGMail/NGMimeMessageGenerator.h>
Expand Down Expand Up @@ -1781,62 +1782,62 @@ - (NSArray *) allBareRecipients
- (NSException *) sendMail
{
SOGoUserDefaults *ud;

ud = [[context activeUser] userDefaults];

if ([ud mailAddOutgoingAddresses])
{
Class contactGCSEntry;
SOGoContactFolders *contactFolders;
SOGoContactFolder *folder;
SOGoContactGCSEntry *newContact;
NGVCard *card;
NGMailAddressParser *parser;
NSArray *matchingContacts;
NSMutableArray *recipients;
NSString *recipient, *emailAddress, *addressBook, *uid;
id parsedRecipient;
int i;

// Get all the addressbooks
contactFolders = [[[context activeUser] homeFolderInContext: context]
lookupName: @"Contacts"
inContext: context
acquire: NO];
// Get all the recipients from the current email
recipients = [self allRecipients];
for (i = 0; i < [recipients count]; i++)
{
// The address contains a string. ex: "John Doe <sogo1@exemple.com>"
recipient = [recipients objectAtIndex: i];
parser = [NGMailAddressParser mailAddressParserWithString: recipient];
parsedRecipient = [parser parse];
emailAddress = [parsedRecipient address];
NSString *recipient, *emailAddress, *addressBook, *uid;
NSArray *matchingContacts, *recipients;
SOGoContactFolders *contactFolders;
SOGoContactGCSEntry *newContact;
NGMailAddress *parsedRecipient;
NGMailAddressParser *parser;
SOGoContactFolder *folder;
NGVCard *card;

int i;

// Get all the addressbooks
contactFolders = [[[context activeUser] homeFolderInContext: context]
lookupName: @"Contacts"
inContext: context
acquire: NO];
// Get all the recipients from the current email
recipients = [self allRecipients];
for (i = 0; i < [recipients count]; i++)
{
// The address contains a string. ex: "John Doe <sogo1@exemple.com>"
recipient = [recipients objectAtIndex: i];
parser = [NGMailAddressParser mailAddressParserWithString: recipient];
parsedRecipient = [parser parse];
emailAddress = [parsedRecipient address];

matchingContacts = [contactFolders allContactsFromFilter: emailAddress
excludeGroups: YES
excludeLists: YES];
}
// If we don't get any results from the autocompletion code, we add it..
if ([matchingContacts count] == 0)
{
// Get the selected addressbook from the user preferences where the new address will be added
addressBook = [ud selectedAddressBook];
folder = [contactFolders lookupName: addressBook inContext: context acquire: NO];
uid = [folder globallyUniqueObjectId];
matchingContacts = [contactFolders allContactsFromFilter: emailAddress
excludeGroups: YES
excludeLists: YES];
}
// If we don't get any results from the autocompletion code, we add it..
if ([matchingContacts count] == 0)
{
// Get the selected addressbook from the user preferences where the new address will be added
addressBook = [ud selectedAddressBook];
folder = [contactFolders lookupName: addressBook inContext: context acquire: NO];
uid = [folder globallyUniqueObjectId];

if (folder && uid)
{
card = [NGVCard cardWithUid: uid];
[card addEmail: emailAddress types: nil];

contactGCSEntry = NSClassFromString(@"SOGoContactGCSEntry");
newContact = [contactGCSEntry objectWithName: uid
inContainer: folder];
[newContact setIsNew: YES];
[newContact saveComponent: card];
}
if (folder && uid)
{
card = [NGVCard cardWithUid: uid];
[card addEmail: emailAddress types: nil];
[card setFn: [parsedRecipient displayName]];

newContact = [SOGoContactGCSEntry objectWithName: uid
inContainer: folder];
[newContact setIsNew: YES];
[newContact saveComponent: card];
}
}
}
}
return [self sendMailAndCopyToSent: YES];
}

Expand Down
2 changes: 1 addition & 1 deletion SoObjects/Mailer/product.plist
@@ -1,5 +1,5 @@
{
requires = ( MAIN );
requires = ( MAIN, Contacts );

publicResources = (
);
Expand Down

2 comments on commit 11adf38

@cgx
Copy link
Contributor

@cgx cgx commented on 11adf38 Sep 17, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have a NEWS entry for bug #2894?

@extrafu
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it should have been done that way right from the start, so no...

Please sign in to comment.