def set_preview(self, sender): if not sender: return viewers = MessageViewer.allMessageViewers() if not viewers: return messages = viewers[0].selectedMessages() if not messages: return preview = CustomizedAttribution.render_attribution( messages[0], messages[0], sender.stringValue(), False) # make newlines visible preview = preview.replace('\n', u'⤦\n') sender.setToolTip_(htmlunescape(preview))
def set_preview(self, sender): if not sender: return viewers = MessageViewer.allMessageViewers() if not viewers: return messages = viewers[0].selectedMessages() if not messages: return preview = CustomizedAttribution.render_attribution( messages[0], messages[0], sender.stringValue(), False ) # make newlines visible preview = preview.replace('\n', u'⤦\n') sender.setToolTip_(htmlunescape(preview))
def finishLoadingEditor(self, original): logger.debug('DocumentEditor finishLoadingEditor') # execute original finishLoadingEditor() original(self) try: # if toggle key is active, temporarily switch the active state is_active = self.app.toggle_key_active ^ self.app.is_active # check if we can proceed if not is_active: logger.debug("QuoteFix is not active, so no QuoteFixing for you!") return # grab composeView instance (this is the WebView which contains the # message editor) and check for the right conditions try: view = objc.getInstanceVariable(self, 'composeWebView') except: # was renamed in Lion view = objc.getInstanceVariable(self, '_composeWebView') # grab some other variables we need to perform our business backend = self.backEnd() htmldom = view.mainFrame().DOMDocument() htmlroot = htmldom.documentElement() messageType = self.messageType() # XXX: hack alert! if message type is DRAFT, but we can determine this # is actually a Send Again action, adjust the message type. origmsg = backend.originalMessage() if origmsg and messageType == DRAFT: # get the message viewer for this message viewer = MessageViewer.existingViewerShowingMessage_(origmsg) if not viewer: # XXX: this happens with conversation view active, not sure if this is stable enough though messageType = SENDAGAIN elif viewer: # get the mailbox for the viewer mailboxes = viewer.selectedMailboxes() # get the Drafts mailbox draftmailbox = viewer.draftsMailbox() # check if they're the same; if not, it's a Send-Again if draftmailbox not in mailboxes: messageType = SENDAGAIN # send original HTML to menu for debugging self.app.html = htmlroot.innerHTML() # should we be quotefixing? if not self.app.is_quotefixing: logger.debug('quotefixing turned off in preferences, skipping that part') elif messageType not in self.app.message_types_to_quotefix: logger.debug('message type "%s" not in %s, not quotefixing' % ( messageType, self.app.message_types_to_quotefix )) else: # remove attachment placeholders? if self.app.remove_attachment_placeholders: self.remove_attachment_placeholders(backend, htmlroot) backend.setHasChanges_(False) # move cursor to end of document view.moveToEndOfDocument_(self) # remove quotes? if self.app.remove_quotes: logger.debug('calling remove_quotes()') self.remove_quotes(htmldom, self.app.remove_quotes_level) backend.setHasChanges_(False) # make quotes selectable? if self.app.selectable_quotes: logger.debug('calling make_selectable_quotes()') self.make_selectable_quotes(view, htmldom) backend.setHasChanges_(False) # remove signature from sender if not self.app.keep_sender_signature: logger.debug('calling remove_old_signature()') if self.remove_old_signature(htmldom, view): backend.setHasChanges_(False) # place cursor above own signature (if any) logger.debug('calling move_above_new_signature()') if self.move_above_new_signature(htmldom, view): backend.setHasChanges_(False) else: view.insertNewline_(self) # perform some general cleanups logger.debug('calling cleanup_layout()') if self.cleanup_layout(htmlroot, backend): backend.setHasChanges_(False) # move cursor to end of document if self.app.move_cursor_to_top: view.moveToBeginningOfDocument_(self) # provide custom attribution? attributor = None if self.app.use_custom_reply_attribution and messageType in [ REPLY, REPLY_ALL, REPLY_AS ]: logger.debug("calling customize_attribution() for reply{-all,-as}") attributor = CustomizedAttribution.customize_reply elif self.app.use_custom_sendagain_attribution and messageType in [ SENDAGAIN ]: logger.debug("calling customize_attribution() for Send Again") attributor = CustomizedAttribution.customize_sendagain elif self.app.use_custom_forwarding_attribution and messageType == FORWARD: logger.debug("calling customize_attribution() for forwarding") attributor = CustomizedAttribution.customize_forward if attributor: # play nice with Attachment Tamer try: message = backend.draftMessage() except: message = backend._makeMessageWithContents_isDraft_shouldSign_shouldEncrypt_shouldSkipSignature_shouldBePlainText_( backend.copyOfContentsForDraft_shouldBePlainText_isOkayToForceRichText_(True, False, True), True, False, False, False, False ) try: for original in objc.getInstanceVariable(backend, '_originalMessages'): attributor( app = self.app, editor = self, dom = htmldom, reply = message, inreplyto = original, ) backend.setHasChanges_(False) except: # ignore when not debugging if self.app.is_debugging: raise # move to beginning of line logger.debug('calling view.moveToBeginningOfLine()') view.moveToBeginningOfLine_(self) # done logger.debug('QuoteFixing done') except Exception: logger.critical(traceback.format_exc()) if self.app.is_debugging: NSRunAlertPanel( 'QuoteFix caught an exception', 'The QuoteFix plug-in caught an exception:\n\n' + traceback.format_exc() + '\nPlease contact the developer quoting the contents of this alert.', None, None, None )
def finishLoadingEditor(self, original): logger.debug('DocumentEditor finishLoadingEditor') # execute original finishLoadingEditor() original(self) try: # if toggle key is active, temporarily switch the active state is_active = self.app.toggle_key_active ^ self.app.is_active # check if we can proceed if not is_active: logger.debug( "MailTrack is not active, so no MailTracking for you!") return # grab composeView instance (this is the WebView which contains the # message editor) and check for the right conditions try: view = objc.getInstanceVariable(self, 'composeWebView') except: # was renamed in Lion view = objc.getInstanceVariable(self, '_composeWebView') # grab some other variables we need to perform our business backend = self.backEnd() htmldom = view.mainFrame().DOMDocument() htmlroot = htmldom.documentElement() messageType = self.messageType() # XXX: hack alert! if message type is DRAFT, but we can determine this # is actually a Send Again action, adjust the message type. origmsg = backend.originalMessage() if origmsg and messageType == DRAFT: # get the message viewer for this message viewer = MessageViewer.existingViewerShowingMessage_(origmsg) if not viewer: # XXX: this happens with conversation view active, not sure if this is stable enough though messageType = SENDAGAIN elif viewer: # get the mailbox for the viewer mailboxes = viewer.selectedMailboxes() # get the Drafts mailbox draftmailbox = viewer.draftsMailbox() # check if they're the same; if not, it's a Send-Again if draftmailbox not in mailboxes: messageType = SENDAGAIN # send original HTML to menu for debugging self.app.html = htmlroot.innerHTML() if not self.app.is_mailtracking: logger.debug( 'mailtracking turned off in preferences, skipping that part' ) elif messageType not in self.app.message_types_to_track: logger.debug('message type "%s" not in %s, not tracking' % (messageType, self.app.message_types_to_track)) else: # move cursor to end of document view.moveToEndOfDocument_(self) # perform some general cleanups logger.debug('calling cleanup_layout()') if self.cleanup_layout(htmlroot, backend): backend.setHasChanges_(False) # move cursor to end of document if self.app.move_cursor_to_top: view.moveToBeginningOfDocument_(self) # move to beginning of line logger.debug('calling view.moveToBeginningOfLine()') view.moveToBeginningOfLine_(self) # done logger.debug('MailTracking done') except Exception: logger.critical(traceback.format_exc()) if self.app.is_debugging: NSRunAlertPanel( 'MailTrack caught an exception', 'The MailTrack plug-in caught an exception:\n\n' + traceback.format_exc() + '\nPlease contact the developer quoting the contents of this alert.', None, None, None)
def finishLoadingEditor(self, original): logger.debug('DocumentEditor finishLoadingEditor') # execute original finishLoadingEditor() original(self) try: # if toggle key is active, temporarily switch the active state is_active = self.app.toggle_key_active ^ self.app.is_active # check if we can proceed if not is_active: logger.debug("MailTrack is not active, so no MailTracking for you!") return # grab composeView instance (this is the WebView which contains the # message editor) and check for the right conditions try: view = objc.getInstanceVariable(self, 'composeWebView') except: # was renamed in Lion view = objc.getInstanceVariable(self, '_composeWebView') # grab some other variables we need to perform our business backend = self.backEnd() htmldom = view.mainFrame().DOMDocument() htmlroot = htmldom.documentElement() messageType = self.messageType() # XXX: hack alert! if message type is DRAFT, but we can determine this # is actually a Send Again action, adjust the message type. origmsg = backend.originalMessage() if origmsg and messageType == DRAFT: # get the message viewer for this message viewer = MessageViewer.existingViewerShowingMessage_(origmsg) if not viewer: # XXX: this happens with conversation view active, not sure if this is stable enough though messageType = SENDAGAIN elif viewer: # get the mailbox for the viewer mailboxes = viewer.selectedMailboxes() # get the Drafts mailbox draftmailbox = viewer.draftsMailbox() # check if they're the same; if not, it's a Send-Again if draftmailbox not in mailboxes: messageType = SENDAGAIN # send original HTML to menu for debugging self.app.html = htmlroot.innerHTML() if not self.app.is_mailtracking: logger.debug('mailtracking turned off in preferences, skipping that part') elif messageType not in self.app.message_types_to_track: logger.debug('message type "%s" not in %s, not tracking' % ( messageType, self.app.message_types_to_track )) else: # move cursor to end of document view.moveToEndOfDocument_(self) # perform some general cleanups logger.debug('calling cleanup_layout()') if self.cleanup_layout(htmlroot, backend): backend.setHasChanges_(False) # move cursor to end of document if self.app.move_cursor_to_top: view.moveToBeginningOfDocument_(self) # move to beginning of line logger.debug('calling view.moveToBeginningOfLine()') view.moveToBeginningOfLine_(self) # done logger.debug('MailTracking done') except Exception: logger.critical(traceback.format_exc()) if self.app.is_debugging: NSRunAlertPanel( 'MailTrack caught an exception', 'The MailTrack plug-in caught an exception:\n\n' + traceback.format_exc() + '\nPlease contact the developer quoting the contents of this alert.', None, None, None )