home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / var / lib / python-support / python2.6 / gdata / apps / migration / service.pyc (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  5.1 KB  |  105 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''Contains the methods to import mail via Google Apps Email Migration API.
  5.  
  6.   MigrationService: Provides methids to import mail.
  7. '''
  8. __author__ = 'google-apps-apis@googlegroups.com'
  9. import base64
  10. import gdata
  11. import gdata.apps.service as gdata
  12. import gdata.service as gdata
  13. from gdata.apps import migration
  14. API_VER = '2.0'
  15.  
  16. class MigrationService(gdata.apps.service.AppsService):
  17.     '''Client for the EMAPI migration service.  Use either ImportMail to import
  18.   one message at a time, or AddBatchEntry and SubmitBatch to import a batch of
  19.   messages at a time.
  20.   '''
  21.     
  22.     def __init__(self, email = None, password = None, domain = None, source = None, server = 'apps-apis.google.com', additional_headers = None):
  23.         gdata.apps.service.AppsService.__init__(self, email = email, password = password, domain = domain, source = source, server = server, additional_headers = additional_headers)
  24.         self.mail_batch = migration.BatchMailEventFeed()
  25.  
  26.     
  27.     def _BaseURL(self):
  28.         return '/a/feeds/migration/%s/%s' % (API_VER, self.domain)
  29.  
  30.     
  31.     def ImportMail(self, user_name, mail_message, mail_item_properties, mail_labels):
  32.         '''Import a single mail message.
  33.  
  34.     Args:
  35.       user_name: The username to import messages to.
  36.       mail_message: An RFC822 format email message.
  37.       mail_item_properties: A list of Gmail properties to apply to the message.
  38.       mail_labels: A list of labels to apply to the message.
  39.  
  40.     Returns:
  41.       A MailEntry representing the successfully imported message.
  42.  
  43.     Raises:
  44.       AppsForYourDomainException: An error occurred importing the message.
  45.     '''
  46.         uri = '%s/%s/mail' % (self._BaseURL(), user_name)
  47.         mail_entry = migration.MailEntry()
  48.         mail_entry.rfc822_msg = migration.Rfc822Msg(text = base64.b64encode(mail_message))
  49.         mail_entry.rfc822_msg.encoding = 'base64'
  50.         mail_entry.mail_item_property = map((lambda x: migration.MailItemProperty(value = x)), mail_item_properties)
  51.         mail_entry.label = map((lambda x: migration.Label(label_name = x)), mail_labels)
  52.         
  53.         try:
  54.             return migration.MailEntryFromString(str(self.Post(mail_entry, uri)))
  55.         except gdata.service.RequestError:
  56.             e = None
  57.             raise gdata.apps.service.AppsForYourDomainException(e.args[0])
  58.  
  59.  
  60.     
  61.     def AddBatchEntry(self, mail_message, mail_item_properties, mail_labels):
  62.         '''Add a message to the current batch that you later will submit.
  63.  
  64.     Args:
  65.       mail_message: An RFC822 format email message.
  66.       mail_item_properties: A list of Gmail properties to apply to the message.
  67.       mail_labels: A list of labels to apply to the message.
  68.  
  69.     Returns:
  70.       The length of the MailEntry representing the message.
  71.     '''
  72.         mail_entry = migration.BatchMailEntry()
  73.         mail_entry.rfc822_msg = migration.Rfc822Msg(text = base64.b64encode(mail_message))
  74.         mail_entry.rfc822_msg.encoding = 'base64'
  75.         mail_entry.mail_item_property = map((lambda x: migration.MailItemProperty(value = x)), mail_item_properties)
  76.         mail_entry.label = map((lambda x: migration.Label(label_name = x)), mail_labels)
  77.         self.mail_batch.AddBatchEntry(mail_entry)
  78.         return len(str(mail_entry))
  79.  
  80.     
  81.     def SubmitBatch(self, user_name):
  82.         '''Send a all the mail items you have added to the batch to the server.
  83.  
  84.     Args:
  85.       user_name: The username to import messages to.
  86.  
  87.     Returns:
  88.       A HTTPResponse from the web service call.
  89.  
  90.     Raises:
  91.       AppsForYourDomainException: An error occurred importing the batch.
  92.     '''
  93.         uri = '%s/%s/mail/batch' % (self._BaseURL(), user_name)
  94.         
  95.         try:
  96.             self.result = self.Post(self.mail_batch, uri, converter = migration.BatchMailEventFeedFromString)
  97.         except gdata.service.RequestError:
  98.             e = None
  99.             raise gdata.apps.service.AppsForYourDomainException(e.args[0])
  100.  
  101.         self.mail_batch = migration.BatchMailEventFeed()
  102.         return self.result
  103.  
  104.  
  105.