2007-11-18 11:16:25 +01:00
|
|
|
/* iCalPerson+SOGo.m - this file is part of SOGo
|
|
|
|
*
|
2015-07-22 22:45:42 +02:00
|
|
|
* Copyright (C) 2007-2015 Inverse inc.
|
2007-11-18 11:16:25 +01:00
|
|
|
*
|
|
|
|
* This file is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This file is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2012-10-22 16:09:13 +02:00
|
|
|
#import <Foundation/NSDictionary.h>
|
2007-11-18 11:16:25 +01:00
|
|
|
#import <Foundation/NSString.h>
|
2012-01-13 18:20:58 +01:00
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
2012-10-22 16:09:13 +02:00
|
|
|
#import <SOGo/SOGoUser.h>
|
|
|
|
#import <SOGo/SOGoUserManager.h>
|
2016-01-18 15:26:07 +01:00
|
|
|
#import <SOGo/SOGoSystemDefaults.h>
|
2007-11-18 11:16:25 +01:00
|
|
|
|
|
|
|
#import "iCalPerson+SOGo.h"
|
|
|
|
|
2009-09-25 16:42:33 +02:00
|
|
|
static SOGoUserManager *um = nil;
|
2007-11-18 11:16:25 +01:00
|
|
|
|
|
|
|
@implementation iCalPerson (SOGoExtension)
|
|
|
|
|
|
|
|
- (NSString *) mailAddress
|
|
|
|
{
|
|
|
|
NSString *cn, *email, *mailAddress;
|
2012-08-27 11:40:18 +02:00
|
|
|
unsigned int len;
|
2007-11-18 11:16:25 +01:00
|
|
|
|
|
|
|
cn = [self cnWithoutQuotes];
|
|
|
|
email = [self rfc822Email];
|
2012-08-27 11:40:18 +02:00
|
|
|
len = [cn length];
|
|
|
|
|
|
|
|
if (len)
|
|
|
|
{
|
|
|
|
// We must check if we have to double-quote properly the person's name,
|
|
|
|
// in case for example we find a comma
|
|
|
|
if ([cn characterAtIndex: 0] != '"' &&
|
|
|
|
[cn characterAtIndex: len-1] != '"' &&
|
|
|
|
[cn rangeOfString: @","].length)
|
|
|
|
mailAddress = [NSString stringWithFormat:@"\"%@\" <%@>", cn, email];
|
|
|
|
else
|
|
|
|
mailAddress = [NSString stringWithFormat:@"%@ <%@>", cn, email];
|
|
|
|
}
|
2007-11-18 11:16:25 +01:00
|
|
|
else
|
|
|
|
mailAddress = email;
|
|
|
|
|
|
|
|
return mailAddress;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) uid
|
|
|
|
{
|
|
|
|
if (!um)
|
2009-09-25 16:42:33 +02:00
|
|
|
um = [SOGoUserManager sharedUserManager];
|
2007-11-18 11:16:25 +01:00
|
|
|
|
|
|
|
return [um getUIDForEmail: [self rfc822Email]];
|
|
|
|
}
|
|
|
|
|
2016-01-18 15:26:07 +01:00
|
|
|
/*
|
|
|
|
It returns the login if the email of the iCalPerson exists on the
|
|
|
|
domain of the current active user
|
|
|
|
*/
|
2015-07-22 22:45:42 +02:00
|
|
|
- (NSString *) uidInContext: (WOContext *) context
|
|
|
|
{
|
|
|
|
NSString *domain;
|
|
|
|
|
|
|
|
domain = [[context activeUser] domain];
|
|
|
|
|
|
|
|
return [self uidInDomain: domain];
|
|
|
|
}
|
|
|
|
|
2016-01-18 15:26:07 +01:00
|
|
|
/*
|
|
|
|
It returns the login if the email of the iCalPerson exists on the
|
|
|
|
given domain
|
|
|
|
*/
|
2015-07-22 22:45:42 +02:00
|
|
|
- (NSString *) uidInDomain: (NSString *) domain
|
|
|
|
{
|
2015-07-23 14:46:08 +02:00
|
|
|
NSDictionary *contact;
|
2016-01-18 15:26:07 +01:00
|
|
|
NSString *uid = nil;
|
2015-07-23 14:46:08 +02:00
|
|
|
|
2015-07-22 22:45:42 +02:00
|
|
|
if (!um)
|
|
|
|
um = [SOGoUserManager sharedUserManager];
|
|
|
|
|
2016-01-18 15:26:07 +01:00
|
|
|
contact = [um contactInfosForUserWithUIDorEmail: [self rfc822Email]
|
|
|
|
inDomain: domain];
|
|
|
|
if (!contact) return nil;
|
|
|
|
|
|
|
|
uid = [contact valueForKey: @"c_uid"];
|
|
|
|
|
|
|
|
// On multidomain environment without DomainLessLogin enabled the login
|
|
|
|
// must have the @domain suffix
|
|
|
|
if ([[SOGoSystemDefaults sharedSystemDefaults] enableDomainBasedUID]
|
|
|
|
&& ![[contact objectForKey: @"DomainLessLogin"] boolValue])
|
|
|
|
uid = [NSString stringWithFormat:@"%@@%@", uid, domain];
|
2015-07-23 14:46:08 +02:00
|
|
|
|
|
|
|
return uid;
|
2015-07-22 22:45:42 +02:00
|
|
|
}
|
|
|
|
|
2012-01-13 18:20:58 +01:00
|
|
|
- (NSString *) contactIDInContext: (WOContext *) context
|
|
|
|
{
|
|
|
|
NSString *domain, *uid;
|
|
|
|
NSArray *contacts;
|
|
|
|
NSDictionary *contact;
|
|
|
|
|
|
|
|
if (!um)
|
|
|
|
um = [SOGoUserManager sharedUserManager];
|
|
|
|
|
|
|
|
uid = nil;
|
|
|
|
domain = [[context activeUser] domain];
|
|
|
|
contacts = [um fetchContactsMatching: [self rfc822Email] inDomain: domain];
|
|
|
|
if ([contacts count] == 1)
|
|
|
|
{
|
|
|
|
contact = [contacts lastObject];
|
|
|
|
uid = [contact valueForKey: @"c_uid"];
|
|
|
|
}
|
|
|
|
|
|
|
|
return uid;
|
|
|
|
}
|
|
|
|
|
2008-11-05 22:04:16 +01:00
|
|
|
- (BOOL) hasSentBy
|
|
|
|
{
|
|
|
|
NSString *mail;
|
|
|
|
|
2009-07-23 19:34:17 +02:00
|
|
|
mail = [self value: 0 ofAttribute: @"SENT-BY"];
|
2008-11-05 22:04:16 +01:00
|
|
|
|
|
|
|
return ([mail length] > 7);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) sentBy
|
|
|
|
{
|
|
|
|
NSString *mail;
|
|
|
|
|
2009-07-23 19:34:17 +02:00
|
|
|
mail = [self value: 0 ofAttribute: @"SENT-BY"];
|
2008-11-05 22:04:16 +01:00
|
|
|
|
|
|
|
if ([mail length] > 7)
|
|
|
|
{
|
2008-11-13 17:03:41 +01:00
|
|
|
if ([mail characterAtIndex: 0] == '"' && [mail hasSuffix: @"\""])
|
2008-11-05 22:04:16 +01:00
|
|
|
mail = [mail substringWithRange: NSMakeRange(1, [mail length]-2)];
|
|
|
|
|
|
|
|
return [mail substringFromIndex: 7];
|
|
|
|
}
|
|
|
|
|
|
|
|
return @"";
|
|
|
|
}
|
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
@end
|