]> err.no Git - scalable-opengroupware.org/blob - SoObjects/SOGo/agenor_emails4uid.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1045 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / SoObjects / SOGo / agenor_emails4uid.m
1 /*
2   Copyright (C) 2005 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
6   OGo is free software; you can redistribute it and/or modify it under
7   the terms of the GNU Lesser General Public License as published by the
8   Free Software Foundation; either version 2, or (at your option) any
9   later version.
10
11   OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12   WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14   License for more details.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with OGo; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21
22 #include "AgenorUserManager.h"
23 #include "common.h"
24
25 static void usage(NSArray *args) {
26   fprintf(stderr, "usage: %s <uid1> <uid2> <uid3>\n",
27           [[args objectAtIndex:0] cString]);
28 }
29
30 static void handleUID(NSString *uid, AgenorUserManager *userManager) {
31   NSArray  *emails;
32   NSString *primary;
33   unsigned i, count;
34   
35   primary = [userManager getEmailForUID:uid];
36   emails  = [userManager getSharedMailboxEMailsForUID:uid];
37   
38   printf("%s:", [uid cString]);
39   
40   if ([primary length] > 0)
41     printf("  %s\n", [primary cString]);
42   else
43     printf("  <no primary email found>\n");
44   
45   if ((count = [emails count]) == 0) {
46     printf("  <no shares with emitter access>\n");
47     return;
48   }
49   
50   for (i = 0; i < count; i++)
51     printf("  %s\n", [[emails objectAtIndex:i] cString]);
52 }
53
54 static void doIt(NSArray *args) {
55   AgenorUserManager *userManager;
56   NSEnumerator *e;
57   NSString     *uid;
58   
59   if ([args count] < 2) {
60     usage(args);
61     return;
62   }
63   
64   userManager = [AgenorUserManager sharedUserManager];
65   
66   e = [args objectEnumerator];
67   [e nextObject]; /* consume the command name */
68   
69   while ((uid = [e nextObject]) != nil)
70     handleUID(uid, userManager);
71 }
72
73 int main(int argc, char **argv, char **env) {
74   NSAutoreleasePool *pool;
75   
76   pool = [[NSAutoreleasePool alloc] init];
77 #if LIB_FOUNDATION_LIBRARY
78   [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
79 #endif
80   
81   doIt([[NSProcessInfo processInfo] argumentsWithoutDefaults]);
82   
83   [pool release];
84   return 0;
85 }