MozillaZine

TB Delete Attachment Extension ( created !)

Talk about add-ons and extension development.
Old Ausdilecce
 
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post Posted May 11th, 2004, 8:09 pm

EDIT EDIT
Lots of changes to this extension since this thread's beginning. If you want to skip to current version

click here --> http://forums.mozillazine.org/viewtopic ... 478#537478


I have created an extension for TB that strips attachments out of messages
and leaves the filename of the attachment(s) in the message

EDIT - things have worked themselves out since I posted this .. look down below for link to xpi

This is how it works

1) I create a temporay folder off the selected folder
2) copy the selected message into the temporary folder
3) open the temporary folder's 'file' that holds that message
4) parse the file, stripping out the attachment data ( file A )
5) open the original folder's file
6) do a search if that file on the text of the original message, replacing it with file A
7) write the original file, with changes, back to disk
8 ) force TB to erase the attachment icon for that message in the thread view
9) delete the temporary folder made in step 1
10) delete that folder from the trash
11) compact the original folder

NOW... it works -- consistently BUT

There are many many ways a message can have attachments

I haven't a clue to the exact ways a message can contain attachments.

HELP NEEDED HERE
I need someone ( with knowledge regarding such ) to help me create an algorithm to strip FILE attachments
and not strip attachments one needs to keep (ex. html )

What I am doing is splitting a message ( source ) into an array, split on \n chars
I will send you source if you want !

Cheers,
Frank
Last edited by Old Ausdilecce on May 21st, 2004, 12:34 am, edited 2 times in total.

bren90

User avatar
 
Posts: 135
Joined: February 28th, 2004, 2:29 pm

Post Posted May 11th, 2004, 9:37 pm

Hi Frank,

To strip out particular attachments, I think all you need to do is parse through the email, looking for lines beginning with Content-Type. This gives the type of attachment. A few lines (3-4, not sure how standard this is) after that, there is a line beginning with filename.

From these two you can generate a list of attachments, with names and types. Then to delete particular attachments, strip from the line before content-type to the next line that begins --.

As added security, the line before content-type, and the line that denotes the end of attachment are the same, and have the same numbers in them. e.g. --------------030403070507010907010305

This might make it easier to program as well, if you read the line before content-type, you can safely delete that line, and up to and including every line until you reach the same line again.

I'd like to see the source as well, if you could send it to me, that would be great.

Thanks again for all this,

Brendan

jhirshon

User avatar
 
Posts: 762
Joined: June 11th, 2003, 3:24 pm

Post Posted May 12th, 2004, 6:57 am

Frank - I (and probably all Tbird users) await this extension with unreal anticipation! :)

One option that would be nice to have - for it to only parse specific folders (Inbox, outbox etc.) - I for one would like to strip all the attachments in my outbox ONLY.

Thanks again for a great extension - JH

Old Ausdilecce
 
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post Posted May 12th, 2004, 8:31 pm

OK, for you brave souls that would like to be the first guinea pigs for the 0.1 version of this

grab the xpi here www.supportware.net/mozilla/DeleteAttachment.xpi

BE VERY CAREFUL WITH THIS as it can create havoc with the folder you are on.

To test ( the careful way)
1) create a subfolder off the folder your attachment-bound message is in
2) COPY the attachment-bound message to the new folder
3) click tools...Delete Attachment n watch it go

A copy of the modified message will be in the trash
the modified message will STILL show the attachment icon
.....( because the headers of the attachments are still present, the DATA of the attachment(s) are gone )
to see that .. press ctrl-U (view message source) prior to tools..delete attachment
... then do ctrl-U after the delete attachment ( or just look at how big the folder file is before and after )

Things you should know :
the menu option will only show up if you have attachments !
you can only delete attachment(s) from one message at a time - sorry
messages sent in both html and text should still be viewed in either mode as I dont strip the HTML attachment
the original message might NOT be selected after a 'delete attachment' operation
this is a first cut so ... be careful

EDIT: after messing around with a couple of different message types I have found that
1) images are cached, meaning that after the attachment is deleted out of a message, the message pane will still show the image(s) !
2) messages with many attachments ( messages > 10MB) might freeze TB .. gotta figure out why/when its happening
..... interestingly, once TB was restarted, the new message was there, correctly fomatted but all attachments gone ( thats a good thing)


Please send any feedback to me.. da_comments..att...supportware.net
Last edited by Old Ausdilecce on May 12th, 2004, 9:19 pm, edited 1 time in total.

Old Ausdilecce
 
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post Posted May 12th, 2004, 8:36 pm

jhirshon wrote:Frank - I (and probably all Tbird users) await this extension with unreal anticipation! :)

One option that would be nice to have - for it to only parse specific folders (Inbox, outbox etc.) - I for one would like to strip all the attachments in my outbox ONLY.

Thanks again for a great extension - JH


Unfortunately JH, It's hard enough doing one message. So no, not at this point can I allow multiple messages to be done at once sorry

Someone on another thread expressed the desire to change the subject text

While this *is* possible, the message summary file (.msf) will not get updated and therefore, the subject text will then be different in the message than that of the message header ( bad bad ).

The ability is still in the code but is disabled until someone can figure out how to rebuild the msf file after the change of subject text.

Cheers to all

SoaRex

User avatar
 
Posts: 369
Joined: April 20th, 2003, 10:01 pm
Location: Japan, the earth, the solar system

Post Posted May 12th, 2004, 9:45 pm

ausdilecce wrote:While this *is* possible, the message summary file (.msf) will not get updated and therefore, the subject text will then be different in the message than that of the message header ( bad bad ).

Compact folder is possibly a way to force ".msf" recreation.
However, Mozilla/Thunderbird does not seem to do comact action if no deleted(but not erased) mail exists in ".msf", since there is no reason to compact.
Copy & delete mails is possibly a solution for this case.

Old Ausdilecce
 
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post Posted May 13th, 2004, 12:56 am

SoaRex wrote:
ausdilecce wrote:While this *is* possible, the message summary file (.msf) will not get updated and therefore, the subject text will then be different in the message than that of the message header ( bad bad ).

Compact folder is possibly a way to force ".msf" recreation.


I would have thought so too. I tried that. I tired copying to, deleting from and every which way to try ( obviously conpacting folders before and after ) and get it to rebuild the msf but to no avail.

SoaRex wrote:However, Mozilla/Thunderbird does not seem to do comact action if no deleted(but not erased) mail exists in ".msf", since there is no reason to compact.
Copy & delete mails is possibly a solution for this case.


As I say, I tried that. Thanks for the help tho.

I have to find a way to do it, for a whole host of other reasons.

SoaRex

User avatar
 
Posts: 369
Joined: April 20th, 2003, 10:01 pm
Location: Japan, the earth, the solar system

Post Posted May 13th, 2004, 3:02 am

ausdilecce wrote:
SoaRex wrote:Compact folder is possibly a way to force ".msf" recreation.

I would have thought so too. I tried that. I tired copying to, deleting from and every which way to try ( obviously conpacting folders before and after ) and get it to rebuild the msf but to no avail.


Another way.

On my Mozilla 1.7 RC1, subject change was automatically doen when I edited folder file.
(1) Start Mozilla Broweser & Mail&News
(2) Open a mail folder "TEST"
=> "TEST.msf" file was opened by Mozilla and was locked
=> Edit of "TEST.msf" is impossible due to the lock
(3) Edit mail folder file (file name = "TEST") by text editor
- Change subject of a mail
- Save file
(4) Click mail folder of "TEST"
=> Subject of mail list pane was changed automatically.

Mozilla does this ".msf" re-creation process if inconsistensy is found between ".msf" file and folder file.
The most simple inconsisitency is time stamp difference and text editor changes last update time stamp of mail folder file.

Are there any way to force this inconsistency from JapaScript of extention?
For example, open folder file("TEST" in my test) and modify(replace by same data) and close the file.

andrea.m
 
Posts: 46
Joined: May 26th, 2003, 4:47 pm

Post Posted May 13th, 2004, 9:01 am

does it work with tb0.6? I can't find the delete attachment menu option

wwwillem
 
Posts: 4
Joined: July 28th, 2003, 9:32 pm

Post Posted May 13th, 2004, 9:01 am

I worked on this myself for a while and indeed the many ways attachments are formatted is pretty confusing.

There are two approaches:

1) Just look for parts in the email with base64 encoding. So check the content-encoding instead of the content-type. These are always the biggies you want to get rid off. Those few html extensions are fine and can stay.

2) I would prefer the solution where "Delete" and "Delete All" are (right-click) options in addition to the existing "Save As" and "Save All". And I even could live without the "Delete All". When "Delete" is just a user choice, you don't have to worry anymore about which attachments to delete. Just let the user decide.

Willem

Old Ausdilecce
 
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post Posted May 13th, 2004, 2:30 pm

SoaRex, I tried that. Unfortunately, the msf file does NOT get updated :(

andrea.m, Yes, it does work with 0.6. THe menu option is in tools... ONLY IF:
1) you are in 3 pane view with the preview pane open ( sorry, this is necessary )
2) you did NOT open the message in its own window
3) you have selected a message with attachments

wwwillem, that's a mighty fine idea ( #1 ) I will look into it
#2 idea is mighty fine too. I just thought that I don't want to bother the user with many popups about which attachments they would like to delete. How would you propose the UI should work re: prompting user for which attachments to strip ?

ALL OF YOU - .. it has come to my attention that :
1) the initial run will do nothing sometimes ( this is because th extension attempts to compact the selected folder as a first step and there is a timing issue if compact folder takes too long so ..
as a workaround -
1) select a folder
2) manually compact that folder
3) then try the deleteAttachment menu command

2) some messages ( big ones over 2 MB ) take a while to copy over to the temp folder and .. yet again .. there is a timing issue ... it seems that the copy succeeds but I start to read the folder file BEFORE the whole message was copied over and so..
the delete attachment function fails AND leaves the temporary folder (delAtttemP) out there with a copy of the selected message in it.
I am working on a fix for this. give me a bit of time.

Old Ausdilecce
 
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post Posted May 14th, 2004, 5:32 pm

OK everyone following this.

After extensive rewriting, the extension is available in 0.2 form.

This is how it works now
1) create a temp folder in local folders/trash
2) copy the selected message there
3) mark the original message as deleted ( original message now resides in trash AND temp folder under trash)
3a) compact the original folder
4) Force the folder closed ( so we can now delete the MSF !!! )
5) open the temp folder's file
6) strip out the attachments
7) open the original folder's file, append the new message (without attachments) on the end of the file
8 ) Delete the original folder's MSF file
9) Delete the TEMP folder ONLY, in trash ( this totally delete's the temp folder, no need to compact trash and the original message is still in trash )
10) Re-open the database ( which re-creates the msf file for that folder )
DONE !

Now the original folder size is updated as it the message size after attachments are stripped
.....( the first cut of DeleteAttachment did not update these properly)

Steps are now timed properly so that really big messages are dealt with properly ( I tested on a message nearly 6 MB and it worked fine)

Subject text *CAN* be changed ( just have to set a prefs.js pref )

Attachment indicators and Icons are still present but filenames now read *erased* + filename so you can see that the attachment is no longer there

the XPI is now on the site --> www.supportware.net/mozilla/DeleteAttachment.xpi

Old Ausdilecce
 
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post Posted May 15th, 2004, 5:30 pm

Someone who shall remain nameless sent in this comment

Warning! Wanted to let you know that I now downloaded and tried the 0.2 version of att.del! I tried it on a message in a folder with 234 messages. Then I clicked on del.att. AFTER this operation I had lost all my e-mails since 30.08.2002!!! They were gone, lost. Compacting folder, erasing MSF, nothing helped!! (I had a copy of my mails from last week, so I could reimport nearly all).

Maybe a timinig issue?? But you better shouldn't use the XPI on large folders (mine was 7,7 MB).

while he did have a backup and all was fine, it did concern me ( obviously :wink: )

I found that the way I was appending the modified message to the original folder's file failed at a certain amount of bytes

I have now modified the extension to a different append method, at just tested on the larges folder I have (47 MB ) and it works fine
.... ( faster too, gotta love that ! )

anyway.. updating the xpi on the site now ( to version 0.2.1 )

I am now working on being able to select more than one message at a time

jimmy73
 
Posts: 47
Joined: May 1st, 2004, 1:25 am

Post Posted May 16th, 2004, 11:56 pm

Hi!
I am the nameless one from the posting above. Just wanted to let anyone know that I wasn't able to reproduce the failure. For me the version 0.2.1. works fine!
Now waiting for the disappearing od the paper-clip symbol :-)

TriEnt

User avatar
 
Posts: 52
Joined: February 26th, 2004, 11:38 pm
Location: Bucharest, RO

Post Posted May 17th, 2004, 12:07 am

jimmy73 wrote:Now waiting for the disappearing od the paper-clip symbol :-)


IMHO the paper-clip symbol should stay there. It's important to leave a trace that the message had once had attachments. I haven't tested the extension yet (waiting for others to confirm it's stable enough first), but if it replaces each original attachment with a blank file with just the same name & " - removed" appended (or something in that line), then that should be just enough.

Return to Extension Development


Who is online

Users browsing this forum: No registered users and 0 guests