~ubuntu-branches/debian/sid/openchange/sid

« back to all changes in this revision

Viewing changes to mapiproxy/services/ocsmanager/ocsmanager/model/NotificationModel.py

  • Committer: Package Import Robot
  • Author(s): Jelmer Vernooij
  • Date: 2012-04-12 20:07:57 UTC
  • mfrom: (11 sid)
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: package-import@ubuntu.com-20120412200757-k933d9trljmxj1l4
Tags: 1:1.0-4
* openchangeserver: Add dependency on openchangeproxy.
* Rebuild against newer version of Samba 4.
* Use dpkg-buildflags.
* Migrate to Git, update Vcs-Git header.
* Switch to debhelper 9.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from pylons import config
 
2
from lxml import etree
 
3
from ocsmanager.lib.utils import validateDocXML
 
4
import re
 
5
 
 
6
class NotificationModel:
 
7
 
 
8
    def getNewMailParams(self, payload):
 
9
        """Retrieve newmail parameters."""
 
10
        (error, xmlData) = validateDocXML(payload)
 
11
        if error is True: return (error, xmlData)
 
12
 
 
13
        # Retrieve MAPIStore management object
 
14
        mgmt = config['mapistore']
 
15
 
 
16
        # Initialize dictionary
 
17
        params = {}
 
18
 
 
19
        # Retrieve notification and ensure it's newmail
 
20
        notification = xmlData.find('notification')
 
21
        if notification is None: return (True, 'Missing Notification')
 
22
        if not 'category' in notification.attrib: return (True, 'Missing notification type')
 
23
        if notification.attrib['category'] != 'newmail': return (True, 'Invalid notification type')
 
24
 
 
25
        # backend parameter
 
26
        param = notification.find('backend')
 
27
        if param is None or param.text is None: return (True, 'Invalid/Missing backend parameter')
 
28
        if mgmt.registered_backend(param.text) is False: return (True, 'Specified backend is invalid')
 
29
        params['backend'] = param.text
 
30
 
 
31
        # folder parameter
 
32
        param = notification.find('folder')
 
33
        if param is None or param.text is None: return (True, 'Invalid/Missing folder parameter')
 
34
        params['folder'] = param.text
 
35
 
 
36
        # messageID parameter
 
37
        param = notification.find('messageID')
 
38
        if param is None or param.text is None: retrun (True, 'Invalid/Missing messageID parameter')
 
39
        params['messageID'] = param.text
 
40
 
 
41
        # username parameter
 
42
        param = notification.find('username')
 
43
        if param is None or param.text is None: return (True, 'Invalid/Missing username parameter')
 
44
        params['vuser'] = param.text
 
45
 
 
46
        # Search for openchange user matching above attributes
 
47
        ed = mgmt.existing_users(params['backend'], params['vuser'], params['folder'])
 
48
        if ed['count'] == 0: return (True, 'Invalid user')
 
49
        print ed
 
50
        count = 0
 
51
        for info in ed['infos']:
 
52
            ret = mgmt.registered_message(params['backend'], info['username'], params['vuser'],
 
53
                                          params['folder'], info['mapistoreURI'], params['messageID'])
 
54
            if ret is True:
 
55
                print 'Message already registered for user %s' % info['username']
 
56
                count = count + 1
 
57
            else:
 
58
                # Register the message in all users indexing databases
 
59
                message = mgmt.register_message(params['backend'], info['username'], 
 
60
                                                info['mapistoreURI'], params['messageID'])
 
61
                if not message: print "Unable to register URI for user %s" % (info['username'])
 
62
                else:
 
63
                    print "[REGISTERED] user %s: (%s, %s)" % (info['username'], hex(message[0]), message[1])
 
64
 
 
65
        # Case where all users referencing this folder already got notified
 
66
        if count == ed['count']: return (True, 'Message already registered')
 
67
 
 
68
        # Only trigger a notification for registered users
 
69
        rd = mgmt.registered_users(params['backend'], param.text)
 
70
        print rd
 
71
        if rd["count"] == 0: return (True, 'User not registered')
 
72
        params['usernames'] = rd["usernames"]
 
73
 
 
74
        # Trigger newmail notification for registered users (rd) who subscribed for newmail Notification
 
75
        for info in ed['infos']:
 
76
            for username in params['usernames']:
 
77
#                print 'Searching for fnevNewmail for %s on %s' % (username, info['mapistoreURI'])
 
78
#                ret = mgmt.registered_subscription(username, info['mapistoreURI'], 1, 4)
 
79
#                if ret is True:
 
80
                print 'Sending newmail notif on /%s#newmail' % username
 
81
                ret = mgmt.send_newmail(username, info['username'], info['mapistoreURI'], message[1])
 
82
                if ret is False:
 
83
                    print 'Error while sending newmail notif'
 
84
 
 
85
        return (False, params)