6

I am using Thunderbird 68 on Debian.

For any email that I send, Thunderbird creates temp files in /tmp:

/tmp/nsmail.tmp
/tmp/nsmail-1.tmp
/tmp/nsmail-2.tmp
/tmp/nscopy.tmp
/tmp/nscopy-1.tmp

Not only are these files not deleted after the email is send, worse still they stay there after Thunderbird is closed.

I have found a bug report both on Ubuntu and Bugzilla, but no solution.

I find it a very bad practice that the temp file is not deleted immediately after email has been sent. And absolutely outrageous, that even application exit does not clean up its temp files.

As a workaround, can I change the location where these temp files are created ? For instance, using ~/.cache/thunderbird/ would be more appropriate.

Martin Vegter
  • 358
  • 75
  • 236
  • 411
  • 1
    Is it for any email, or just emails with attachments? Have you tried setting the TMP environment variable to point to e.g. $HOME/.cache/thunderbird before starting Thunderbird? – telcoM Apr 13 '20 at 09:32
  • @telcoM - it happens for all emails, not just with attachment. And the file nsmail-1.tmp is created not while editing, but after the email is sent. – Martin Vegter Apr 13 '20 at 10:07
  • @telcoM - setting TMP actually works. – Martin Vegter Apr 13 '20 at 10:08
  • 1
    You can always do something like thunderbird; rm /tmp/nsmail* /tmp/nscopy*. If you start thunderbird from GUI you can replace $(command -v thunderbird) with a wrapper. Of course ideally this bug should be solved in Thunderbird itself https://bugzilla.mozilla.org/show_bug.cgi?id=1589890 – Arkadiusz Drabczyk Apr 13 '20 at 13:44
  • You fail to understand the sticky permission and lack the understanding for operating systems and the fhs. TMP in the profile is NOT a "workaround". But since you dont want to set the environment variable, where are the other complaints? ALL apps will use the system tmp! There is only one way left. Settings for Thunderbird! – WGRM Apr 15 '20 at 09:18
  • I updated my answer. – WGRM Apr 15 '20 at 09:24
  • Because the current version is 78.* I have to mention THE real problem. If TB is used long enough to accumulate 10000 such files in the TEMP directory, so it has all the files from nsemail.eml to nsemail-9999.eml, Thunderbird will suddenly stop sending e-mails with an error. It can be solved by simply deleting the files.

    The system: Win7SP164bit with now latest TB 78.8.0. We met this problem earlier on some Win 7 and 10 systems with mixed TB versions, and unknowing the real cause we solved the problem by removing TB, cleaning the system and meanwhile cleaning the temp folders as well.

    – Tylla Mar 05 '21 at 14:35

2 Answers2

2

This bug was introduced in v68.x and it is not yet fixed. After investigation here is the exact situation:

Bug detail:

Thunderbird do use ~/tmp/ns* since earlier version when sending email, but it also do delete those temporary files just after using them, while tb is still open. On v68.x a coding mistake make thunderbird try to delete those temporary files on the location /tmp/ns... instead of ~/tmp/ns... thus setting $TMPDIR variable to /tmp fix the issue. (awaiting an upstream update)

Solution:

Using the following command to run Thunderbird will fix the issue (similar to the other answer)

export TMPDIR=/tmp; thunderbird;
intika
  • 14,406
  • I have modified the Exec line in my thunderbird.desktop file: Exec=env TMPDIR=/tmp /usr/bin/thunderbird. Thunderbird now uses /tmp for those garbage files, but does not delete them. The files are there, even after exit. – Martin Vegter Apr 16 '20 at 08:21
  • @400theCat i did re tested v68.7.0 from https://download.mozilla.org/?product=thunderbird-68.7.0-SSL&os=linux64 and when using it with export TMPDIR=/tmp; ./thunderbird the temporary file get deleted just after the message get sent otherwise with the default config, tmp files do remain on ~/tmp.. what's the your version ? can you try with the latest official one (v68.7.0) from the given link (just extract it and run it from there cd extracted-path; export TMPDIR=/tmp; ./thunderbird)... otherwise the other answer may be useful, it can be combined with a loop timer to delete the temp files – intika Apr 16 '20 at 09:06
  • nmy TB version is 68.6.0. As I wrote, I am not using export. I am using Exec=env TMPDIR=/tmp /usr/bin/thunderbird in my thunderbird.desktop file – Martin Vegter Apr 16 '20 at 12:46
  • @400theCat just tested 68.6.0 with pop3 and imap... it's the same behavior, i don't know why this does not work on your system... at least Exec=env TMPDIR=/tmp /usr/bin/thunderbird; rm -rf /tmp/ns*; may be used to delete those files after tb is closed... otherwise something like Exec=env TMPDIR=/tmp /usr/bin/thunderbird & some-script.sh where the script would contain some thing like [while true; sleep 60; if /tmp/ns*; sleep 60; rm -rf /tmp/ns*; done] i updated the first answer to add the script with exact syntax. – intika Apr 16 '20 at 15:47
1

This bug was introduced in v68.x and it is not yet fixed, awaiting this to be fixed here is a workaround, note that tmp/ns* files are required for TB v68 to work correctly.

Workaround I:

As suggested on the comments a custom temporary file can be used, you can then apply different restrictions to that specific temporary folder, also note that the environment variable changes does not need to be applied widely.

Edit the .desktop file used to run Thunderbird (usually under /usr/share/applications) by changing the Exec= line to the following command or launch Thunderbird with the given command:

export TMPDIR=/home/my/new/tmpdir; export TMP=$TMPDIR; thunderbird; rm -rf /home/my/new/tmpdir/ns*

This will set $TMPDIR and $TMP variable to a custom location, then Thunderbird is run and finally when it's closed rm -rf /home/my/new/tmpdir/ns* will delete tmp leftover.

Note that env. variable changes will just affect Thunderbird if this is ran from a bash or .desktop file. Otherwise if this command is ran directly from a terminal changes to $TMP will affect commands launched after this command.

Workaround II:

We can use a script to do the job manually while Thunderbird is used; To do so we would edit the .desktop file with the following:

Exec=env TMPDIR=/tmp /usr/bin/thunderbird & /path/to/watch-tb-script.sh

Where cat watch-tb-script.sh would be:

#!/bin/sh

[[ $(ps all -e | grep thunderbird | grep -v color | grep -v grep) ]]
while [[ "$?" == 0 ]] 
do
  for i in /tmp/ns*; do 
    if [ -f "$i" ]; then 
      rm -rf $i;
      sleep 10s; 
    fi;
  done;
  sleep 60s;
  [[ $(ps all -e | grep thunderbird | grep -v color | grep -v grep) ]]
done;

This script will keep running while thunderbird is opened, check for /tmp/ns* files and do remove each file every 10 sec then the script will sleep 60 sec before the next check.

intika
  • 14,406
  • why do I need to export both TMPDIR and TMP ? – Martin Vegter Apr 16 '20 at 03:01
  • Yeah, you will get errors on compacting big msgboxes. – WGRM Apr 16 '20 at 03:24
  • @400theCat Thunderbird uses mainly $TMPDIR as a source to get the temporary directory location but it also uses $TMP in other cases (https://dxr.mozilla.org/thunderbird/search?q=getenv(%22TMP%22)&redirect=true)... it is better to set both variables, but it's not required. – intika Apr 16 '20 at 03:36
  • @400theCat i added a new workaround by editing this answer ;) – intika Apr 16 '20 at 15:42