PageRenderTime 26ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/gdata/apps/emailsettings/service.py

https://bitbucket.org/jasonrglasgow/gdata
Python | 264 lines | 245 code | 2 blank | 17 comment | 0 complexity | abee22365f184ce6fb0fb5c028a5c34e 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. """Allow Google Apps domain administrators to set users' email settings.
  17. EmailSettingsService: Set various email settings.
  18. """
  19. __author__ = 'google-apps-apis@googlegroups.com'
  20. import gdata.apps
  21. import gdata.apps.service
  22. import gdata.service
  23. API_VER='2.0'
  24. # Forwarding and POP3 options
  25. KEEP='KEEP'
  26. ARCHIVE='ARCHIVE'
  27. DELETE='DELETE'
  28. ALL_MAIL='ALL_MAIL'
  29. MAIL_FROM_NOW_ON='MAIL_FROM_NOW_ON'
  30. class EmailSettingsService(gdata.apps.service.PropertyService):
  31. """Client for the Google Apps Email Settings service."""
  32. def _serviceUrl(self, setting_id, username, domain=None):
  33. if domain is None:
  34. domain = self.domain
  35. return '/a/feeds/emailsettings/%s/%s/%s/%s' % (API_VER, domain, username,
  36. setting_id)
  37. def CreateLabel(self, username, label):
  38. """Create a label.
  39. Args:
  40. username: User to create label for.
  41. label: Label to create.
  42. Returns:
  43. A dict containing the result of the create operation.
  44. """
  45. uri = self._serviceUrl('label', username)
  46. properties = {'label': label}
  47. return self._PostProperties(uri, properties)
  48. def CreateFilter(self, username, from_=None, to=None, subject=None,
  49. has_the_word=None, does_not_have_the_word=None,
  50. has_attachment=None, label=None, should_mark_as_read=None,
  51. should_archive=None):
  52. """Create a filter.
  53. Args:
  54. username: User to create filter for.
  55. from_: Filter from string.
  56. to: Filter to string.
  57. subject: Filter subject.
  58. has_the_word: Words to filter in.
  59. does_not_have_the_word: Words to filter out.
  60. has_attachment: Boolean for message having attachment.
  61. label: Label to apply.
  62. should_mark_as_read: Boolean for marking message as read.
  63. should_archive: Boolean for archiving message.
  64. Returns:
  65. A dict containing the result of the create operation.
  66. """
  67. uri = self._serviceUrl('filter', username)
  68. properties = {}
  69. properties['from'] = from_
  70. properties['to'] = to
  71. properties['subject'] = subject
  72. properties['hasTheWord'] = has_the_word
  73. properties['doesNotHaveTheWord'] = does_not_have_the_word
  74. properties['hasAttachment'] = gdata.apps.service._bool2str(has_attachment)
  75. properties['label'] = label
  76. properties['shouldMarkAsRead'] = gdata.apps.service._bool2str(should_mark_as_read)
  77. properties['shouldArchive'] = gdata.apps.service._bool2str(should_archive)
  78. return self._PostProperties(uri, properties)
  79. def CreateSendAsAlias(self, username, name, address, reply_to=None,
  80. make_default=None):
  81. """Create alias to send mail as.
  82. Args:
  83. username: User to create alias for.
  84. name: Name of alias.
  85. address: Email address to send from.
  86. reply_to: Email address to reply to.
  87. make_default: Boolean for whether this is the new default sending alias.
  88. Returns:
  89. A dict containing the result of the create operation.
  90. """
  91. uri = self._serviceUrl('sendas', username)
  92. properties = {}
  93. properties['name'] = name
  94. properties['address'] = address
  95. properties['replyTo'] = reply_to
  96. properties['makeDefault'] = gdata.apps.service._bool2str(make_default)
  97. return self._PostProperties(uri, properties)
  98. def UpdateWebClipSettings(self, username, enable):
  99. """Update WebClip Settings
  100. Args:
  101. username: User to update forwarding for.
  102. enable: Boolean whether to enable Web Clip.
  103. Returns:
  104. A dict containing the result of the update operation.
  105. """
  106. uri = self._serviceUrl('webclip', username)
  107. properties = {}
  108. properties['enable'] = gdata.apps.service._bool2str(enable)
  109. return self._PutProperties(uri, properties)
  110. def UpdateForwarding(self, username, enable, forward_to=None, action=None):
  111. """Update forwarding settings.
  112. Args:
  113. username: User to update forwarding for.
  114. enable: Boolean whether to enable this forwarding rule.
  115. forward_to: Email address to forward to.
  116. action: Action to take after forwarding.
  117. Returns:
  118. A dict containing the result of the update operation.
  119. """
  120. uri = self._serviceUrl('forwarding', username)
  121. properties = {}
  122. properties['enable'] = gdata.apps.service._bool2str(enable)
  123. if enable is True:
  124. properties['forwardTo'] = forward_to
  125. properties['action'] = action
  126. return self._PutProperties(uri, properties)
  127. def UpdatePop(self, username, enable, enable_for=None, action=None):
  128. """Update POP3 settings.
  129. Args:
  130. username: User to update POP3 settings for.
  131. enable: Boolean whether to enable POP3.
  132. enable_for: Which messages to make available via POP3.
  133. action: Action to take after user retrieves email via POP3.
  134. Returns:
  135. A dict containing the result of the update operation.
  136. """
  137. uri = self._serviceUrl('pop', username)
  138. properties = {}
  139. properties['enable'] = gdata.apps.service._bool2str(enable)
  140. if enable is True:
  141. properties['enableFor'] = enable_for
  142. properties['action'] = action
  143. return self._PutProperties(uri, properties)
  144. def UpdateImap(self, username, enable):
  145. """Update IMAP settings.
  146. Args:
  147. username: User to update IMAP settings for.
  148. enable: Boolean whether to enable IMAP.
  149. Returns:
  150. A dict containing the result of the update operation.
  151. """
  152. uri = self._serviceUrl('imap', username)
  153. properties = {'enable': gdata.apps.service._bool2str(enable)}
  154. return self._PutProperties(uri, properties)
  155. def UpdateVacation(self, username, enable, subject=None, message=None,
  156. contacts_only=None):
  157. """Update vacation settings.
  158. Args:
  159. username: User to update vacation settings for.
  160. enable: Boolean whether to enable vacation responses.
  161. subject: Vacation message subject.
  162. message: Vacation message body.
  163. contacts_only: Boolean whether to send message only to contacts.
  164. Returns:
  165. A dict containing the result of the update operation.
  166. """
  167. uri = self._serviceUrl('vacation', username)
  168. properties = {}
  169. properties['enable'] = gdata.apps.service._bool2str(enable)
  170. if enable is True:
  171. properties['subject'] = subject
  172. properties['message'] = message
  173. properties['contactsOnly'] = gdata.apps.service._bool2str(contacts_only)
  174. return self._PutProperties(uri, properties)
  175. def UpdateSignature(self, username, signature):
  176. """Update signature.
  177. Args:
  178. username: User to update signature for.
  179. signature: Signature string.
  180. Returns:
  181. A dict containing the result of the update operation.
  182. """
  183. uri = self._serviceUrl('signature', username)
  184. properties = {'signature': signature}
  185. return self._PutProperties(uri, properties)
  186. def UpdateLanguage(self, username, language):
  187. """Update user interface language.
  188. Args:
  189. username: User to update language for.
  190. language: Language code.
  191. Returns:
  192. A dict containing the result of the update operation.
  193. """
  194. uri = self._serviceUrl('language', username)
  195. properties = {'language': language}
  196. return self._PutProperties(uri, properties)
  197. def UpdateGeneral(self, username, page_size=None, shortcuts=None, arrows=None,
  198. snippets=None, str=None):
  199. """Update general settings.
  200. Args:
  201. username: User to update general settings for.
  202. page_size: Number of messages to show.
  203. shortcuts: Boolean whether shortcuts are enabled.
  204. arrows: Boolean whether arrows are enabled.
  205. snippets: Boolean whether snippets are enabled.
  206. unicode: Wheter unicode is enabled.
  207. Returns:
  208. A dict containing the result of the update operation.
  209. """
  210. uri = self._serviceUrl('general', username)
  211. properties = {}
  212. if page_size != None:
  213. properties['pageSize'] = str(page_size)
  214. if shortcuts != None:
  215. properties['shortcuts'] = gdata.apps.service._bool2str(shortcuts)
  216. if arrows != None:
  217. properties['arrows'] = gdata.apps.service._bool2str(arrows)
  218. if snippets != None:
  219. properties['snippets'] = gdata.apps.service._bool2str(snippets)
  220. if str != None:
  221. properties['unicode'] = gdata.apps.service._bool2str(str)
  222. return self._PutProperties(uri, properties)