File: SOGoAPIUserFolder.m

package info (click to toggle)
sogo 5.12.4-1.2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 103,828 kB
  • sloc: objc: 122,550; javascript: 75,288; sh: 2,352; ansic: 2,055; perl: 861; python: 777; sql: 307; makefile: 187; php: 43; xml: 27
file content (110 lines) | stat: -rw-r--r-- 2,722 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
  Copyright (C) todo...
*/

#import <SOGoAPIUserFolder.h>

#import <GDLContentStore/GCSFolderManager.h>
#import <GDLContentStore/GCSFolder.h>

@implementation SOGoAPIUserFolder

- (id) init
{
  [super init];

  return self;
}

- (void) dealloc
{
  [super dealloc];
}

/**



{
   "calendar":[
      {
         "name":"DidyShared",
         "url":"http://127.0.0.1/SOGo/dav/sogo-tests1@example.org/Calendar/12509-67F67D00-1-3105AF40"
      },
      {
         "name":"LocalDidy",
         "url":"http://127.0.0.1/SOGo/dav/sogo-tests1@example.org/Calendar/1BC38-67B60000-1-6E4B6880"
      },
      {
         "name":"Personal Calendar",
         "url":"http://127.0.0.1/SOGo/dav/sogo-tests1@example.org/Calendar/personal"
      }
   ],
   "username":"sogo-tests1@example.org",
   "contact":[
      {
         "name":"Personal Address Book",
         "url":"http://127.0.0.1/SOGo/dav/sogo-tests1@example.org/Contacts/personal"
      }
   ]
}
**/

- (NSDictionary *) action: (WOContext*) ctx withParam: (NSDictionary *) param
{
  NSDictionary* result;
  NSArray *folders;
  NSMutableArray *cardavLinks, *caldavLinks;
  NSString *serverUrl, *basePath, *c_uid, *url;
  GCSFolderManager *fm;
  GCSFolder *folder;

  int max, i;

  //Should be a user
  c_uid = [[[param objectForKey: @"user"] objectForKey: @"emails"] objectAtIndex: 0];

  //fetch folders
  fm = [GCSFolderManager defaultFolderManager];
  basePath = [NSString stringWithFormat: @"/Users/%@", c_uid];
  folders = [fm listSubFoldersAndNamesAtPath: basePath recursive: YES];

  //Generate dav link
  max = [folders count];
  serverUrl = [[ctx serverURL] absoluteString];

  cardavLinks = [NSMutableArray array];
  caldavLinks = [NSMutableArray array];
  serverUrl = [[ctx serverURL] absoluteString];
  for (i = 0; i < max; i++)
  {
    NSMutableDictionary *folderRet;
    folderRet = [NSMutableDictionary dictionary];
    folder = [folders objectAtIndex: i];
    url = [NSString stringWithFormat: @"%@/SOGo/dav/%@/%@", serverUrl, c_uid, [folder objectForKey: @"path"]];
    [folderRet setObject: url forKey: @"url"];
    [folderRet setObject: [folder objectForKey: @"name"] forKey: @"name"];
    if([url rangeOfString:@"/Calendar/"].location == NSNotFound)
    {
      //Contacts
      [cardavLinks addObject: folderRet];
    }
    else
    {
      //Calendar
      [caldavLinks addObject: folderRet];
    }
  }

  result = [[NSDictionary alloc] initWithObjectsAndKeys:
                                    c_uid,  @"username",
                                    cardavLinks, @"contact",
                                    caldavLinks, @"calendar",
                                    nil];

  [result autorelease];
  return result;
}


@end /* SOGoAPIVersion */