/gdata/apps/emailsettings/service.py
Python | 264 lines | 245 code | 2 blank | 17 comment | 0 complexity | e81b7fdf259fcdab4bdbb8f2d17023a0 MD5 | raw file
1#!/usr/bin/python 2# 3# Copyright (C) 2008 Google, Inc. 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17"""Allow Google Apps domain administrators to set users' email settings. 18 19 EmailSettingsService: Set various email settings. 20""" 21 22__author__ = 'google-apps-apis@googlegroups.com' 23 24 25import gdata.apps 26import gdata.apps.service 27import gdata.service 28 29 30API_VER='2.0' 31# Forwarding and POP3 options 32KEEP='KEEP' 33ARCHIVE='ARCHIVE' 34DELETE='DELETE' 35ALL_MAIL='ALL_MAIL' 36MAIL_FROM_NOW_ON='MAIL_FROM_NOW_ON' 37 38 39class EmailSettingsService(gdata.apps.service.PropertyService): 40 """Client for the Google Apps Email Settings service.""" 41 42 def _serviceUrl(self, setting_id, username, domain=None): 43 if domain is None: 44 domain = self.domain 45 return '/a/feeds/emailsettings/%s/%s/%s/%s' % (API_VER, domain, username, 46 setting_id) 47 48 def CreateLabel(self, username, label): 49 """Create a label. 50 51 Args: 52 username: User to create label for. 53 label: Label to create. 54 55 Returns: 56 A dict containing the result of the create operation. 57 """ 58 uri = self._serviceUrl('label', username) 59 properties = {'label': label} 60 return self._PostProperties(uri, properties) 61 62 def CreateFilter(self, username, from_=None, to=None, subject=None, 63 has_the_word=None, does_not_have_the_word=None, 64 has_attachment=None, label=None, should_mark_as_read=None, 65 should_archive=None): 66 """Create a filter. 67 68 Args: 69 username: User to create filter for. 70 from_: Filter from string. 71 to: Filter to string. 72 subject: Filter subject. 73 has_the_word: Words to filter in. 74 does_not_have_the_word: Words to filter out. 75 has_attachment: Boolean for message having attachment. 76 label: Label to apply. 77 should_mark_as_read: Boolean for marking message as read. 78 should_archive: Boolean for archiving message. 79 80 Returns: 81 A dict containing the result of the create operation. 82 """ 83 uri = self._serviceUrl('filter', username) 84 properties = {} 85 properties['from'] = from_ 86 properties['to'] = to 87 properties['subject'] = subject 88 properties['hasTheWord'] = has_the_word 89 properties['doesNotHaveTheWord'] = does_not_have_the_word 90 properties['hasAttachment'] = gdata.apps.service._bool2str(has_attachment) 91 properties['label'] = label 92 properties['shouldMarkAsRead'] = gdata.apps.service._bool2str(should_mark_as_read) 93 properties['shouldArchive'] = gdata.apps.service._bool2str(should_archive) 94 return self._PostProperties(uri, properties) 95 96 def CreateSendAsAlias(self, username, name, address, reply_to=None, 97 make_default=None): 98 """Create alias to send mail as. 99 100 Args: 101 username: User to create alias for. 102 name: Name of alias. 103 address: Email address to send from. 104 reply_to: Email address to reply to. 105 make_default: Boolean for whether this is the new default sending alias. 106 107 Returns: 108 A dict containing the result of the create operation. 109 """ 110 uri = self._serviceUrl('sendas', username) 111 properties = {} 112 properties['name'] = name 113 properties['address'] = address 114 properties['replyTo'] = reply_to 115 properties['makeDefault'] = gdata.apps.service._bool2str(make_default) 116 return self._PostProperties(uri, properties) 117 118 def UpdateWebClipSettings(self, username, enable): 119 """Update WebClip Settings 120 121 Args: 122 username: User to update forwarding for. 123 enable: Boolean whether to enable Web Clip. 124 Returns: 125 A dict containing the result of the update operation. 126 """ 127 uri = self._serviceUrl('webclip', username) 128 properties = {} 129 properties['enable'] = gdata.apps.service._bool2str(enable) 130 return self._PutProperties(uri, properties) 131 132 def UpdateForwarding(self, username, enable, forward_to=None, action=None): 133 """Update forwarding settings. 134 135 Args: 136 username: User to update forwarding for. 137 enable: Boolean whether to enable this forwarding rule. 138 forward_to: Email address to forward to. 139 action: Action to take after forwarding. 140 141 Returns: 142 A dict containing the result of the update operation. 143 """ 144 uri = self._serviceUrl('forwarding', username) 145 properties = {} 146 properties['enable'] = gdata.apps.service._bool2str(enable) 147 if enable is True: 148 properties['forwardTo'] = forward_to 149 properties['action'] = action 150 return self._PutProperties(uri, properties) 151 152 def UpdatePop(self, username, enable, enable_for=None, action=None): 153 """Update POP3 settings. 154 155 Args: 156 username: User to update POP3 settings for. 157 enable: Boolean whether to enable POP3. 158 enable_for: Which messages to make available via POP3. 159 action: Action to take after user retrieves email via POP3. 160 161 Returns: 162 A dict containing the result of the update operation. 163 """ 164 uri = self._serviceUrl('pop', username) 165 properties = {} 166 properties['enable'] = gdata.apps.service._bool2str(enable) 167 if enable is True: 168 properties['enableFor'] = enable_for 169 properties['action'] = action 170 return self._PutProperties(uri, properties) 171 172 def UpdateImap(self, username, enable): 173 """Update IMAP settings. 174 175 Args: 176 username: User to update IMAP settings for. 177 enable: Boolean whether to enable IMAP. 178 179 Returns: 180 A dict containing the result of the update operation. 181 """ 182 uri = self._serviceUrl('imap', username) 183 properties = {'enable': gdata.apps.service._bool2str(enable)} 184 return self._PutProperties(uri, properties) 185 186 def UpdateVacation(self, username, enable, subject=None, message=None, 187 contacts_only=None): 188 """Update vacation settings. 189 190 Args: 191 username: User to update vacation settings for. 192 enable: Boolean whether to enable vacation responses. 193 subject: Vacation message subject. 194 message: Vacation message body. 195 contacts_only: Boolean whether to send message only to contacts. 196 197 Returns: 198 A dict containing the result of the update operation. 199 """ 200 uri = self._serviceUrl('vacation', username) 201 properties = {} 202 properties['enable'] = gdata.apps.service._bool2str(enable) 203 if enable is True: 204 properties['subject'] = subject 205 properties['message'] = message 206 properties['contactsOnly'] = gdata.apps.service._bool2str(contacts_only) 207 return self._PutProperties(uri, properties) 208 209 def UpdateSignature(self, username, signature): 210 """Update signature. 211 212 Args: 213 username: User to update signature for. 214 signature: Signature string. 215 216 Returns: 217 A dict containing the result of the update operation. 218 """ 219 uri = self._serviceUrl('signature', username) 220 properties = {'signature': signature} 221 return self._PutProperties(uri, properties) 222 223 def UpdateLanguage(self, username, language): 224 """Update user interface language. 225 226 Args: 227 username: User to update language for. 228 language: Language code. 229 230 Returns: 231 A dict containing the result of the update operation. 232 """ 233 uri = self._serviceUrl('language', username) 234 properties = {'language': language} 235 return self._PutProperties(uri, properties) 236 237 def UpdateGeneral(self, username, page_size=None, shortcuts=None, arrows=None, 238 snippets=None, unicode=None): 239 """Update general settings. 240 241 Args: 242 username: User to update general settings for. 243 page_size: Number of messages to show. 244 shortcuts: Boolean whether shortcuts are enabled. 245 arrows: Boolean whether arrows are enabled. 246 snippets: Boolean whether snippets are enabled. 247 unicode: Wheter unicode is enabled. 248 249 Returns: 250 A dict containing the result of the update operation. 251 """ 252 uri = self._serviceUrl('general', username) 253 properties = {} 254 if page_size != None: 255 properties['pageSize'] = str(page_size) 256 if shortcuts != None: 257 properties['shortcuts'] = gdata.apps.service._bool2str(shortcuts) 258 if arrows != None: 259 properties['arrows'] = gdata.apps.service._bool2str(arrows) 260 if snippets != None: 261 properties['snippets'] = gdata.apps.service._bool2str(snippets) 262 if unicode != None: 263 properties['unicode'] = gdata.apps.service._bool2str(unicode) 264 return self._PutProperties(uri, properties)