Thunderbird: copying a message's contents - Mozilla

This is a discussion on Thunderbird: copying a message's contents - Mozilla ; Hi, I'm trying to write an extension for Thunderbird that will allow me to select a message in the list, and hit ctrl+c (or whatever your OS's flavor of copy key-combination happens to be) to copy that entire message, including ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: Thunderbird: copying a message's contents

  1. Thunderbird: copying a message's contents

    Hi,

    I'm trying to write an extension for Thunderbird that will allow me to
    select a message in the list, and hit ctrl+c (or whatever your OS's
    flavor of copy key-combination happens to be) to copy that entire
    message, including all headers, into the clipboard. I don't know how
    userful this would be to anyone else, but I, in my work, would find it
    immensely useful.

    I already know how (thanks to the "thunderbird: getting message body"
    thread) to get the message contents, and I know how to stick it into the
    system clipboard, but where I'm lost is how I go about registering the
    key combination and listener on the message list window so that 'Copy'
    will be enabled in the edit menu.

    I'm rather new to writing extensions for the Mozilla platform, so any
    help you can provide would be immensely useful.

    Regards,

    Adrian

  2. Re: Thunderbird: copying a message's contents

    Adrian Overbury wrote:

    > I already know how (thanks to the "thunderbird: getting message body"
    > thread) to get the message contents, and I know how to stick it into
    > the system clipboard, but where I'm lost is how I go about registering
    > the key combination and listener on the message list window so that
    > 'Copy' will be enabled in the edit menu.


    Copy is a bit of a special case. What you need here is a command
    controller. Start by looking at how the FolderPaneController intercepts
    the Select All command.

    --
    Warning: May contain traces of nuts.

  3. Re: Thunderbird: copying a message's contents

    Neil wrote:
    > Adrian Overbury wrote:
    >
    >> I already know how (thanks to the "thunderbird: getting message body"
    >> thread) to get the message contents, and I know how to stick it into
    >> the system clipboard, but where I'm lost is how I go about registering
    >> the key combination and listener on the message list window so that
    >> 'Copy' will be enabled in the edit menu.

    >
    > Copy is a bit of a special case. What you need here is a command
    > controller. Start by looking at how the FolderPaneController intercepts
    > the Select All command.
    >


    I'm assuming that this command controller would need to be attached to
    the ThreadPaneController? I'm still trying to figure all this out.
    From the example you pointed me to, I can see that I need to override
    specific parts of the command controller that's already there.

    -- supportsCommand can be left alone
    -- isCommandEnabled needs to have cmd_copy return true; and
    -- doCommand needs to have another case added for cmd_copy that will
    perform my task

    Am I even able to override things this specifically? I'm not even sure
    if what I want to do is feasible.

    Also, as a side note for a possible addition to this, is it possible to
    detect if the message I've just grabbed is mime-multipart and, if so, to
    find all text/plain components, find out what encoding they have -- if
    any -- decode them back to utf-8 or some other plain text format?

    Regards,

    Adrian

  4. Re: Thunderbird: copying a message's contents

    Adrian Overbury wrote:

    > Neil wrote:
    >
    >> Adrian Overbury wrote:
    >>
    >>> I already know how (thanks to the "thunderbird: getting message
    >>> body" thread) to get the message contents, and I know how to stick
    >>> it into the system clipboard, but where I'm lost is how I go about
    >>> registering the key combination and listener on the message list
    >>> window so that 'Copy' will be enabled in the edit menu.

    >>
    >> Copy is a bit of a special case. What you need here is a command
    >> controller. Start by looking at how the FolderPaneController
    >> intercepts the Select All command.

    >
    > I'm assuming that this command controller would need to be attached to
    > the ThreadPaneController? I'm still trying to figure all this out.
    > From the example you pointed me to, I can see that I need to override
    > specific parts of the command controller that's already there.


    Any window or (focusable) XUL element can have any number of
    controllers. (I'm not actually sure what you mean by ThreadPaneController.)

    --
    Warning: May contain traces of nuts.

  5. Re: Thunderbird: copying a message's contents

    Adrian Overbury wrote:

    > Well, the DOM Inspector for Thunderbird told me that the individual
    > mail messages are listed in the threadPaneBox, whereas the various
    > accounts and their associated folders, as well as the local folders,
    > are listed in the folderPaneBox.


    They're actually listed in the threadTree and the folderTree respectively.

    > The associated controller for the folderPaneBox is the
    > FolderPaneController, and so the controller I would want is actually
    > the ThreadPaneController, which apparently does exist. Am I looking
    > at the wrong thing here?


    I agree as far as the folder pane controller is concerned, but there is
    no specific thread pane controller, instead the default controller
    handles all the commands that you think of as applying to the thread pane.

    > my gut feeling is that I would create my controller using the same
    > template as things like FolderPaneController, and have my extension
    > add my custom controller to that. By doing that, am I overriding any
    > isCommandEnabled and doCommand sections set by ThreadPaneController?


    It depends on which commands you claim to support. Controllers work like
    this: When JavaScript and/or XBL wants to invoke a controller, it first
    looks at the focused element. If that element is an HTML text input or
    textarea, or it is a XUL element, then it may have one or more
    controllers. Each controller is queried to see if it supports the
    desired command. If no controller for the command is found at the focus,
    the window is then queried, and, in the case of a frame, ancestor
    windows are also queried. As soon as a controller is found it is then
    queried to see if the command is enabled. If the command is enabled then
    it is executed. If the command is disabled then nothing happens. Either
    way no other controllers are queried.

    In the case of the copy command, the only controllers that currently
    support the copy command are the built-in ones that deal with selections
    in windows, HTML text inputs or textareas. If you add your controller to
    the thread pane then your controller will supersede the built-in one
    whenever the thread pane has focus. Alternatively you could add your
    controller to the window, but you would have to insert it in front of
    the built-in controller which would otherwise handle it, and it would
    not take effect if the focus was in any frame (such as the message) or
    text box (such as the quick search box) but it would still work if the
    focus was on the thread pane. In fact the select all command works this
    way - if you press Ctrl+A when the focus is in the message or a text box
    then only that gets selected, otherwise all the messages in the thread
    pane get selected.

    --
    Warning: May contain traces of nuts.

+ Reply to Thread