def get_attachments(self): """ returns messages attachments Derived from the leaves of the email mime tree that and are not part of :rfc:`2015` syntax for encrypted/signed mails and either have :mailheader:`Content-Disposition` `attachment` or have :mailheader:`Content-Disposition` `inline` but specify a filename (as parameter to `Content-Disposition`). :rtype: list of :class:`Attachment` """ if not self._attachments: self._attachments = [] for part in self.get_message_parts(): cd = part.get('Content-Disposition', '') filename = part.get_filename() ct = part.get_content_type() # replace underspecified mime description by a better guess if ct in ['octet/stream', 'application/octet-stream']: content = part.get_payload(decode=True) ct = helper.guess_mimetype(content) if cd.startswith('attachment'): if ct not in ['application/pgp-encrypted', 'application/pgp-signature']: self._attachments.append(Attachment(part)) elif cd.startswith('inline'): if filename != None and ct != 'application/pgp': self._attachments.append(Attachment(part)) return self._attachments
def upload_attachment(instance_id, property_name): logger.debug('receiving attachment \'' + property_name + '\' for instance ' + instance_id) attachment = Attachment(instance_id, property_name, request) if attachment.save(): status = 200 else: status = 400 return Response(attachment.json_status, mimetype=_JSON_MIME, status=status)
def load_attachment(instance_id, property_name): logger.debug('serving attachment \'' + property_name + '\' for instance ' + instance_id) attachment = Attachment(instance_id, property_name, request) generator = attachment.load() if generator is not None: return Response(generator(), mimetype=_BINARY_MIME, status=200) else: return Response(attachment.json_status, mimetype=_JSON_MIME, status=404)
def __init__(self, ref, thruster_keys, r, distx, disty): Attachment.__init__(self, ref, r, distx, disty) self.sprite = pil_process(os.path.join("images", "thrust.png")) self.sprite_r = self.sprite.get_width()/2 self.sprite_scaling = 1.5 self.thruster_keys = thruster_keys self.repr = "Thruster" self.dist = self.dist+self.r*self.sprite_scaling
def prepare_email_content(email_address, subject): #construct Receiver, Content and Attachment Class r = Receiver() c = Content() a = Attachment() msg = EmailMessage() msg['Subject'] = subject msg['To'] = ', '.join(r.get_receiver()) msg['From'] = email_address msg.set_content(c.get_content()) set_attachment(msg, a.get_attachments()) return msg
def run() -> None: logging.basicConfig(level=logging.DEBUG) reader = ExcelReader() raw_candidates = reader.read_candidates_from_excel() candidates = create_candidates(raw_candidates) attachments = Attachment() attachments.add_attachment(candidates) client = HuntFlowClient() upload_resumes(candidates, client) add_candidates_to_db(candidates, client) add_candidates_to_vacancy(candidates, client) return
def serialize_as_explanation(self, transaction_url, project_url): attachment = Attachment(self.filename) result = { 'bank_transaction_explanation': { 'bank_transaction': transaction_url, 'description': self.description, 'category': self.guessed_category, 'gross_value': str(0 - self.amount), # Required 'project': project_url, 'dated_on': self.date.isoformat(), 'rebill_type': None, 'attachment': attachment.serialize(), } } # LOG.info(json.dumps(result, indent=4)) return result
def serialize_as_expense(self, user_url, project_url): attachment = Attachment(self.filename) result = { 'expense': { 'user': user_url, # Required 'category': self.guessed_category, 'gross_value': str(0 - self.amount), # Required 'currency': 'GBP', 'description': self.description, # Required 'dated_on': self.date.isoformat(), # Required 'manual_sales_tax_amount': '0.00', 'project': project_url, 'rebill_type': None, 'attachment': attachment.serialize(), } } return result
def get_all_files(self): (status, result) = self._send_template_request('getAllFiles', {'task_id': self.id}) if status and result: files = [] for file_info in result: files.append(Attachment(self, file_info)) return files else: return False
def attachments(self): attachments = [] for part in self.walk(): if part.get_content_maintype() == 'multipart': continue filename = part.get_filename() if not filename: continue data = part.get_payload(decode=True) attachments.append(Attachment(filename=self._decode_string( filename ), data=data, mime_type=part.get_content_type())) return attachments
def _process_message_attachments(self, attachment_list): # Parse the attachments of an MMS message attachments = [] for current_attachment in attachment_list: embed_item = getattr(current_attachment, "embed_item", None) if embed_item is not None: plus_photo = getattr(embed_item, "embeds.PlusPhoto.plus_photo", None) if plus_photo is not None: current_attachment = Attachment() current_attachment.album_id = self._try_int_attribute( plus_photo, "album_id") current_attachment.photo_id = self._try_int_attribute( plus_photo, "photo_id") current_attachment.media_type = getattr( plus_photo, "media_type", None) current_attachment.original_content_url = getattr( plus_photo, "original_content_url", None) current_attachment.download_url = getattr( plus_photo, "download_url", None) attachments.append(current_attachment) return attachments
def attach(self, attachment, filename=None, ctype=None): """ attach a file :param attachment: File to attach, given as :class:`~alot.db.attachment.Attachment` object or path to a file. :type attachment: :class:`~alot.db.attachment.Attachment` or str :param filename: filename to use in content-disposition. Will be ignored if `path` matches multiple files :param ctype: force content-type to be used for this attachment :type ctype: str """ if isinstance(attachment, Attachment): self.attachments.append(attachment) elif isinstance(attachment, basestring): path = os.path.expanduser(attachment) part = helper.mimewrap(path, filename, ctype) self.attachments.append(Attachment(part)) else: raise TypeError('attach accepts an Attachment or str') if self.sent_time: self.modified_since_sent = True
from favorite import Favorite from followers import followers from hypeline import Hypeline from picture import Picture from rehype import Rehype from role import Role from trending import Trending from user import User from hypeblock import Hypeblock from dislike import dislike from hypes import Hype from login import Login app = Flask(__name__) app.secret_key = 'A0Z//hdfg^+%j/3yX R~XHHsadfaf]LWX/,?RT' app.attachment=Attachment(app) app.block=block(app) app.contacts=Contact(app) app.favorite=Favorite(app) app.followers=followers(app) app.hypeline=Hypeline(app) app.picture=Picture(app) app.rehype=Rehype(app) app.role=Role(app) app.trending=Trending(app) app.user=User(app) app.hypeblock=Hypeblock(app) app.dislike=dislike(app) app.hype=Hype(app) app.login=Login(app)