def importFromFile(self, path): data = file(path, "rb").read() (mimeType, encoding) = mimetypes.guess_type(path) self.photoBody = utils.dataToBinary(self, 'photoBody', data, mimeType=mimeType)
def importFromURL(self, url): if isinstance(url, URL): url = str(url) data = urllib.urlopen(url).read() (mimeType, encoding) = mimetypes.guess_type(url) self.photoBody = utils.dataToBinary(self, 'photoBody', data, mimeType=mimeType)
def __getMailMessage(self): if self.__mailMessage is not None: return self.__mailMessage view = self.rep.view m = Mail.MailMessage(view=view) m.fromAddress = Mail.EmailAddress(view=view) m.fromAddress.emailAddress = "*****@*****.**" toOne = Mail.EmailAddress(view=view) toOne.emailAddress = "*****@*****.**" toTwo = Mail.EmailAddress(view=view) toTwo.emailAddress = "*****@*****.**" toTwo.fullName = "John Johnson" m.toAddress = [] m.toAddress.append(toOne) m.toAddress.append(toTwo) ccOne = Mail.EmailAddress(view=view) ccOne.emailAddress = "*****@*****.**" m.ccAddress = [] m.ccAddress.append(ccOne) m.subject = "test mail" m.headers['Content-Length'] = "75" m.headers['Content-Type'] = "text/plain; charset=utf-8; format=flowed" m.headers['Content-Transfer-Encoding'] = "7bit" m.headers['Mime-Version'] = "1.0" m.headers[ 'Received'] = "from [192.168.101.37] (w002.z065106067.sjc-ca.dsl.cnc.net [65.106.67.2]) by kahuna.osafoundation.org (8.12.8/8.12.8) with ESMTP id i7GKWWpo017020; Mon, 16 Aug 2004 13:32:32 -0700" m.headers[ 'References'] = "<*****@*****.**> <*****@*****.**> <*****@*****.**> <*****@*****.**>" dateString = "Mon, 9 Aug 2004 13:55:15 -0700" m.dateSent = datetime.fromtimestamp( mktime(emailUtils.parsedate(dateString))) m.dateSentString = dateString m.body = utils.unicodeToText(m, "body", u"This is the body") m.rfc2822Message = utils.dataToBinary(m, "rfc2822Message", self.__mail) self.__mailMessage = m return self.__mailMessage
def __getMailMessage(self): if self.__mailMessage is not None: return self.__mailMessage view = self.rep.view m = Mail.MailMessage(view=view) m.fromAddress = Mail.EmailAddress(view=view) m.fromAddress.emailAddress = "*****@*****.**" toOne = Mail.EmailAddress(view=view) toOne.emailAddress = "*****@*****.**" toTwo = Mail.EmailAddress(view=view) toTwo.emailAddress = "*****@*****.**" toTwo.fullName = "John Johnson" m.toAddress = [] m.toAddress.append(toOne) m.toAddress.append(toTwo) ccOne = Mail.EmailAddress(view=view) ccOne.emailAddress = "*****@*****.**" m.ccAddress = [] m.ccAddress.append(ccOne) m.subject = "test mail" m.headers['Content-Length'] = "75" m.headers['Content-Type'] = "text/plain; charset=utf-8; format=flowed" m.headers['Content-Transfer-Encoding'] = "7bit" m.headers['Mime-Version'] = "1.0" m.headers['Received'] = "from [192.168.101.37] (w002.z065106067.sjc-ca.dsl.cnc.net [65.106.67.2]) by kahuna.osafoundation.org (8.12.8/8.12.8) with ESMTP id i7GKWWpo017020; Mon, 16 Aug 2004 13:32:32 -0700" m.headers['References'] = "<*****@*****.**> <*****@*****.**> <*****@*****.**> <*****@*****.**>" dateString = "Mon, 9 Aug 2004 13:55:15 -0700" m.dateSent = datetime.fromtimestamp(mktime(emailUtils.parsedate(dateString))) m.dateSentString = dateString m.body = utils.unicodeToText(m, "body", u"This is the body") m.rfc2822Message = utils.dataToBinary(m, "rfc2822Message", self.__mail) self.__mailMessage = m return self.__mailMessage
def __getMailMessage(self, addNewLine=False): view = self.view m = Mail.MailMessage(itsView=view) m.fromAddress = Mail.EmailAddress.getEmailAddress(view, "*****@*****.**") toOne = Mail.EmailAddress.getEmailAddress(view, "*****@*****.**") toTwo = Mail.EmailAddress.getEmailAddress(view, "*****@*****.**", "John Johnson") m.toAddress = [] m.toAddress.append(toOne) m.toAddress.append(toTwo) ccOne = Mail.EmailAddress.getEmailAddress(view, "*****@*****.**") m.ccAddress = [] m.ccAddress.append(ccOne) m.subject = "test mail" if addNewLine: m.subject += "\n" m.headers['Content-Length'] = "75" m.headers['Content-Type'] = "text/plain; charset=utf-8; format=flowed" m.headers['Content-Transfer-Encoding'] = "7bit" m.headers['Mime-Version'] = "1.0" m.headers['Received'] = "from [192.168.101.37] (w002.z065106067.sjc-ca.dsl.cnc.net [65.106.67.2]) by kahuna.test.com (8.12.8/8.12.8) with ESMTP id i7GKWWpo017020; Mon, 16 Aug 2004 13:32:32 -0700" m.headers['References'] = "<*****@*****.**> <*****@*****.**> <*****@*****.**> <*****@*****.**>" dateString = "Mon, 9 Aug 2004 13:55:15 -0700" m.dateSent = datetime.fromtimestamp(emailUtils.mktime_tz(emailUtils.parsedate_tz(dateString)), view.tzinfo.getInstance("Etc/GMT-7")) m.dateSentString = dateString m.itsItem.body = u"This is the body" if not IGNORE_ATTACHMENTS: m.rfc2822Message = utils.dataToBinary(m, "rfc2822Message", self.__mail) self.__mailMessage = m return self.__mailMessage
def _importValues(self, dom, view, element, item, stampClasses, activity, stats): for valueElement in dom.iterElements(element): attrs = dom.getAttributes(valueElement) attrName = attrs['name'] status = attrs.get('status') if status == 'nil': if item.hasLocalAttributeValue(attrName): delattr(item, attrName) continue attribute = item.itsKind.getAttribute(attrName, False, item) otherName = attribute.getAspect('otherName') cardinality = attribute.getAspect('cardinality') attrType = attribute.getAspect('type') # This code depends on attributes having their type set, # which might not always be the case. What should be # done is to encode the value type into the shared xml # itself: if otherName or isinstance(attrType, Kind): if cardinality == 'single': for child in dom.iterElements(valueElement): valueItem = self.importProcess(dom, child) if valueItem is not None: setattr(item, attrName, valueItem) elif cardinality == 'list': count = 0 for child in dom.iterElements(valueElement): valueItem = self.importProcess(dom, child) if valueItem is not None: count += 1 item.addValue(attrName, valueItem) if not count: # Only set to an empty ref collection if # attrName is not already an empty ref # collection needToSet = True if item.hasLocalAttributeValue(attrName): if len(getattr(item, attrName)) == 0: needToSet = False if needToSet: setattr(item, attrName, []) elif cardinality == 'dict': pass else: # it's a literal if cardinality == 'single': mimeType = attrs.get('mimetype') encoding = attrs.get('encoding') or 'utf-8' content = dom.getContent(valueElement) if mimeType: # Lob indexed = mimeType == "text/plain" value = base64.b64decode(content) value = mailUtils.dataToBinary(item, attrName, value, mimeType, 'bz2', indexed) if encoding: value.encoding = encoding else: value = attrType.makeValue(content) setattr(item, attrName, value) elif cardinality == 'list': values = [] for child in dom.iterElements(valueElement): mimeType = dom.getAttribute(child, 'mimetype') if mimeType: # Lob indexed = mimeType == "text/plain" value = base64.b64decode(child.children[0]) value = mailUtils.dataToBinary(item, attrName, value, mimeType, 'bz2', indexed) encoding = dom.getAttribute(child, 'encoding') if encoding: value.encoding = encoding else: content = dom.getContent(child) value = attrType.makeValue(content) values.append(value) setattr(item, attrName, values) elif cardinality == 'dict': pass
def _importValues(self, dom, view, element, item, stampClasses, activity, stats): for valueElement in dom.iterElements(element): attrs = dom.getAttributes(valueElement) attrName = attrs['name'] status = attrs.get('status') if status == 'nil': if item.hasLocalAttributeValue(attrName): delattr(item, attrName) continue attribute = item.itsKind.getAttribute(attrName, False, item) otherName = attribute.getAspect('otherName') cardinality = attribute.getAspect('cardinality') attrType = attribute.getAspect('type') # This code depends on attributes having their type set, # which might not always be the case. What should be # done is to encode the value type into the shared xml # itself: if otherName or isinstance(attrType, Kind): if cardinality == 'single': for child in dom.iterElements(valueElement): valueItem = self.importProcess(dom, child) if valueItem is not None: setattr(item, attrName, valueItem) elif cardinality == 'list': count = 0 for child in dom.iterElements(valueElement): valueItem = self.importProcess(dom, child) if valueItem is not None: count += 1 item.addValue(attrName, valueItem) if not count: # Only set to an empty ref collection if # attrName is not already an empty ref # collection needToSet = True if item.hasLocalAttributeValue(attrName): if len(getattr(item, attrName)) == 0: needToSet = False if needToSet: setattr(item, attrName, []) elif cardinality == 'dict': pass else: # it's a literal if cardinality == 'single': mimeType = attrs.get('mimetype') encoding = attrs.get('encoding') or 'utf-8' content = dom.getContent(valueElement) if mimeType: # Lob indexed = mimeType == "text/plain" value = base64.b64decode(content) value = mailUtils.dataToBinary(item, attrName, value, mimeType, 'bz2', indexed) if encoding: value.encoding = encoding else: value = attrType.makeValue(content) setattr(item, attrName, value) elif cardinality == 'list': values = [] for child in dom.iterElements(valueElement): mimeType = dom.getAttribute(child, 'mimetype') if mimeType: # Lob indexed = mimeType == "text/plain" value = base64.b64decode(child.children[0]) value = mailUtils.dataToBinary( item, attrName, value, mimeType, 'bz2', indexed) encoding = dom.getAttribute(child, 'encoding') if encoding: value.encoding = encoding else: content = dom.getContent(child) value = attrType.makeValue(content) values.append(value) setattr(item, attrName, values) elif cardinality == 'dict': pass