LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-10-2020, 01:20 PM   #1
Michael Uplawski
Senior Member
 
Registered: Dec 2015
Posts: 1,621
Blog Entries: 40

Rep: Reputation: Disabled
[Mutt] save HTML-Mail in a raw text file


Good evening

Let me try to keep this simple. First I tell you what I want, then I tell you what I did and describe the results which, so far, are unsatisfactory. Chances are, you do not understand me anyway... PSE stick to what I note in my subject-line, above: Mutt. This is my mail-client which I use in a terminal-emulator.

What I want
I receive HTML-mail and there is a newsletter in HTML that I am particularly interested in. I attach the latest issue to this post with headers and all (be brave, if you want to read the source). This type of mail is displayed in mutt with the help of the w3m text-browser. Here is a screen-shot.

What I dream of is a way to store a readable text-version of such mail in a file.
What I did
For the time I tried to pipe the mail through commands, directly from mutt (using the pipe symbol '|') or to convert either the eml-file or only the html-content with html2text or a2ps and ps-filters (which are ghostscript, if I have understood anything).

The result is always awful.

I do clearly not know, what I am doing.

While w3m and mutt are a perfect match and display something halfway readable, my attempts appear to fail due to the Content-Transfer-Encoding quoted-printable. I can understand that html2text is not interested in quoted-printable and a2ps will transform what it gets, all encoding and tags intact.

The best that I can come up with is the output from my own tool “maillinks”, which extracts links (hidden ones, especially) from html-mail and references complete URLs below the text. I used html2text on this result and put it in the attachment maillinks-output.
If you know something better
PSE tell me. But remember : this is about Mutt.
Attached Thumbnails
Click image for larger version

Name:	sc_gmf_mutt_via_w3m.png
Views:	62
Size:	69.6 KB
ID:	33621  
Attached Files
File Type: txt gmfmail.eml.txt (110.2 KB, 23 views)
File Type: txt maillinks_output.txt (31.1 KB, 28 views)

Last edited by Michael Uplawski; 07-10-2020 at 01:50 PM. Reason: Added the actual objective of the exercise.
 
Old 07-10-2020, 01:58 PM   #2
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
Perhaps, pipe the output from mutt through qprint -d or process the .eml file with ripmime before feeding the result to html2txt or to w3m -dump?

Last edited by shruggy; 07-10-2020 at 02:41 PM.
 
1 members found this post helpful.
Old 07-10-2020, 02:52 PM   #3
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,137
Blog Entries: 6

Rep: Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826
If you are opening that in w3m, then

~/.w3m/keymap
Code:
keymap P PRINT
I opened this forum page, hit P, and specified a file name, it saved the page as file.txt. The text looks like the way w3m displays it.

I've changed my keymap all around. It may not be P on yours.
 
1 members found this post helpful.
Old 07-10-2020, 03:09 PM   #4
Michael Uplawski
Senior Member
 
Registered: Dec 2015
Posts: 1,621

Original Poster
Blog Entries: 40

Rep: Reputation: Disabled
Thanks @Shruggy and @teckk.

A major difficulty arises from the fact that mutt lets w3m only handle the body of the mail (<body></body>). w3m and html2text are apparently confused with the mail-source.

@shruggy: I installed qprint and it does a nice job, once that I can handle the mail-body in HTML-format.
@teckk: w3m opens the mail, if I store it in a file, first, like a pager is expected to do it, as raw text, with all tags intact. To change this behavior, I must limit the content to the HTML body part only.

During my trials with qprint, I came up with the idea to open the original mail for editing, i.e. by hitting the key 'e' in mutt. Then, in my editor, which is vim, I enter the command-line
Code:
!ruby -e "puts '<body>' << File.read('%').split('<body>')[1].split('</body>')[0] << '</body>'"|qprint -d|html2text
and it does the job. This is intentionally clumsy, as I have
1. no intention to use it
2. no idea about how clean it up.

Last edited by Michael Uplawski; 07-10-2020 at 04:21 PM. Reason: more words. qprint. Not QPDF... thick fingers.
 
Old 07-10-2020, 03:20 PM   #5
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
Well, you can always force w3m to handle the file as HTML with -T text/html.
Code:
sed -E '0,/^-{6}/d;/^-{6},$d' gmfmail.eml.txt|
qprint -d|
w3m -dump -T text/html
And ripmime extracts the HTML attachment decoding QP in the process.
Code:
mkdir out
ripmime -i gmfmail.eml.txt -d out

Last edited by shruggy; 07-10-2020 at 03:21 PM.
 
1 members found this post helpful.
Old 07-10-2020, 04:18 PM   #6
Michael Uplawski
Senior Member
 
Registered: Dec 2015
Posts: 1,621

Original Poster
Blog Entries: 40

Rep: Reputation: Disabled
Quote:
Originally Posted by shruggy View Post
Well, you can always force w3m to handle the file as HTML with -T text/html.
Code:
qprint -d | w3m -T text/html
can be followed by the PRINT-command as teckk has shown above. But the mail-headers are still present in the decoded content.

Code:
out=`mktemp -d`
ripmime -i - -d $out
It is cumbersome to write a shell-script because ripmime must write to a text-file. I am not sure that I can then always identify the right file as file-names are allocated automatically.

But I have progressed with these hints.

P.S.: I is 23h22 in Europe and I have to be up early tomorrow... Thank you for this quick exchange. I will open the thread again tomorrow.

Last edited by Michael Uplawski; 07-10-2020 at 04:25 PM. Reason: $out.
 
Old 07-10-2020, 04:31 PM   #7
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,137
Blog Entries: 6

Rep: Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826
I took a look at that gmfmail.eml.txt

I removed the mail header from it, run it through sed 's/=09//'g
Saved it as an html file. Any web browser will open it now.

Code:
curl -F'file=@muttmail.png' https://0x0.st
https://0x0.st/itSi.png
That a xterm/w3m window colored my way.

Then to get the text from it:
Code:
html2text --ignore-tables muttmail.html
     
**En ouvrant cette newsletter ou en cliquant sur "affic= her les images", vous
acceptez l'utilisation de cookies pour vous = proposer des offres
personnalis=C3=A9es. Pour en savoir plus sur les cookie= s GMF et leurs
r=C3=A9glages, cliquez [ici](3D"http://links.mail6.spopess=).**  
La newsletter Ma vie ASSUR=C3= =89MENT  
**Si vous avez des difficult=C3= =A9s pour visualiser ce message, acc=C3=A9dez
=C3=A0 la[ version en ligne](3D"http://l=).  
N'oubliez pas d'ajouter : = [info.md-client@gmf-assurances.=
fr](3D"mailto:info.md-client@gmf-assurances.fr") =C3=A0 votre carnet d'adresse
!**  
  
  
     
[![3D"GMF"](3D'http://content.mail6.spopessentials6.com/ra/2020/1720=)](3D"http://links.mail6.spope=)  
[![3D"Ma](3D'http://content.mail6.spopessentials6.com/ra/=)](3D"http://links.ma=)  
[![3D"Ma](3D'http://content.mail6.spopessent=)](3D"http://links.mail6.spopess=)  
**Juillet** 202= 0  
Votre n° de soci=C3=A9tair= e : 000H472699  
  
![3D"Facebook"](3D'http://content.mail6.spopessentials6.c=)
![3D"Twitter"](3D'http://content.mail6.spopessentials6.c=)
Or
Code:
html2text --ignore-tables --ignore-links muttmail.html
     
**En ouvrant cette newsletter ou en cliquant sur "affic= her les images", vous
acceptez l'utilisation de cookies pour vous = proposer des offres
personnalis=C3=A9es. Pour en savoir plus sur les cookie= s GMF et leurs
r=C3=A9glages, cliquez ici.**  
La newsletter Ma vie ASSUR=C3= =89MENT  
**Si vous avez des difficult=C3= =A9s pour visualiser ce message, acc=C3=A9dez
=C3=A0 la version en ligne.  
N'oubliez pas d'ajouter : = info.md-client@gmf-assurances.= fr =C3=A0 votre
carnet d'adresse !**  
  
  
     
![3D"GMF"](3D'http://content.mail6.spopessentials6.com/ra/2020/1720=)  
![3D"Ma](3D'http://content.mail6.spopessentials6.com/ra/=)  
![3D"Ma](3D'http://content.mail6.spopessent=)  
**Juillet** 202= 0  
Votre n° de soci=C3=A9tair= e : 000H472699  
  
![3D"Facebook"](3D'http://content.mail6.spopessentials6.c=)
![3D"Twitter"](3D'http://content.mail6.spopessentials6.c=)
![3D"LinkedIn"=](3D'http://content.mail6.spopessentials6.=)
![3D"YouTube"](3D'http://content.mail6.spopessentials6.c=)  
![3D"On](3D'http://content.ma=)  
= <= font style=3D"color:#55bdfe;">On aime  
  
  
![3D"Les](3D'http://content.mail6.spopessentials6.co=)  
     
**Je prends soin de moi** =  
  
**TMS  : tous expos=C3=A9s, tous concern= =C3=A9s**  
  
Les Troubles Musculo-Squelettiques (TMS= ) repr=C3=A9sentent 87 % des mal=
adies professionnelles en France. Que vous soyez hospitaliers, enseignants,=
policiers, gendarmes, militaires ou agents de la fonction publique territo=
riale, vous avez tous fourni un travail acharn=C3=A9 ces derniers mois pour=
faire face =C3=A0 la crise sanitaire. Votre corps a =C3=A9t=C3=A9 mis =C3= =A0
rude =C3=A9preuve et vous souffrez peut-=C3=AAtre de TMS. Pour mieux le= s
comprendre et pr=C3=A9venir leur apparition, nos explications en images
 
1 members found this post helpful.
Old 07-10-2020, 04:57 PM   #8
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
This is my result
Code:
$  sed -n '/^<!/,/^<\/html>/p' gmfmail.eml.txt|qprint -d|w3m -dump -T text/html

       En ouvrant cette newsletter ou en cliquant sur "afficher les images", vous
     acceptez l'utilisation de cookies pour vous proposer des offres personnalisées.
         Pour en savoir plus sur les cookies GMF et leurs réglages, cliquez ici.
                             La newsletter Ma vie ASSURÉMENT
      Si vous avez des difficultés pour visualiser ce message, accédez à la version
                                        en ligne.
        N'oubliez pas d'ajouter : info.md-client@gmf-assurances.fr à votre carnet
                                       d'adresse !


     GMF
     Ma vie assurément                                                  Juillet 2020
                Ma vie assurément                Votre n° de sociétaire : 000H472699

                                                   Facebook Twitter LinkedIn YouTube
                                         On aime
                                         On aime

                                    Les TMS

     Je prends soin de moi

     TMS : tous exposés, tous concernés

     Les Troubles Musculo-Squelettiques (TMS) représentent 87 % des maladies
     professionnelles en France. Que vous soyez hospitaliers, enseignants,
     policiers, gendarmes, militaires ou agents de la fonction publique
     territoriale, vous avez tous fourni un travail acharné ces derniers mois pour
     faire face à la crise sanitaire. Votre corps a été mis à rude épreuve et vous
     souffrez peut-être de TMS. Pour mieux les comprendre et prévenir leur
     apparition, nos explications en images.

           On vous dit tout en vidéo

                                    Morceaux choisis
                                    Morceaux choisis

                   Sur la route                                 Prix Littéraire

         Sur la route                                  Mon agenda

         Pour une route plus sûre                      Première édition du Prix
                                                       Littéraire Europe 1–GMF
         En ce début juillet, vous serez
         nombreux à prendre la route des               S'engager auprès des autres, agir
         vacances. Mais avant de pouvoir               en faveur de l'intérêt général...
         profiter de votre séjour, faites              Pour mettre à l'honneur le
         preuve d'une grande vigilance au              collectif, la solidarité et les
         volant. Pour vous y aider, GMF et             valeurs humaines, la radio
         Waze ont choisi de vous adresser              Europe 1 et GMF s'associent pour
         1 001 conseils pendant votre                  récompenser les ouvrages qui
         parcours.                                     racontent la vie de ceux qui
             Découvrez comment                         œuvrent à rendre la société plus
                                                       humaine.
                                                           Je lis le palmarès


                 Ma vie connectée                                  Vacances

         Ma vie connectée                              Mes moments clés

         Top 5 des applis pour mieux                   Des vacances en toute sérénité
         appréhender la nature
                                                       Vous êtes sur le point de partir
         Vous vous apprêtez à passer des               pour des vacances de rêve ?
         vacances en pleine nature ? Que               Avez-vous pensé à tout ? Avant de
         vous soyez fan de randonnées,                 mettre les voiles, il est
         amoureux de la cueillette,                    préférable de bien vous
         spécialiste animalier ou passionné            organiser : sécuriser votre lieu
         par les constellations, voici les             d'habitation, effectuer tous les
         applis dont vous ne pourrez plus              contrôles avant de prendre la
         vous séparer.                                 route et vous assurer d'avoir tout
          Mes applis dans la poche                     ce dont vous pourriez avoir besoin
                                                       (documents, numéros utiles) ...
                                                            Suivez le guide


                        PNF                                       Bien manger

         Ma vie de sociétaire                          Je prends soin de moi

         Les parcs nationaux de France vous            Bien manger coûte-t-il vraiment
         ouvrent leurs portes                          plus cher ?

         Vous ne savez pas encore quelle               Avec les beaux jours, on pourrait
         destination privilégier pour vos              être tenté de changer nos
         vacances ? Partez à la découverte             habitudes et de manger plus
         des merveilles de notre patrimoine            sainement. Seulement, pour
         naturel en explorant l'un des 11              beaucoup, « mieux manger » rime
         parcs nationaux de France.                    souvent avec surcoût. Si cette
         Répartis sur tout le territoire,              idée se révèle parfois exacte, il
         en métropole et en outre-mer, ils             est tout à fait possible de bien
         regorgent d'une incroyable                    manger sans dépenser plus.
         biodiversité.                                      On vous explique
          Partez à leur découverte


                                      GMF en actes
                                      GMF en actes

                      Merci aux agents du service public

                                       #solidarité

           Merci à tous ceux qui, hier comme aujourd'hui, se sont mobilisés et
       continueront de s'engager pour chacun d'entre nous. Personnels soignants et
        sapeurs-pompiers au service des patients, agents de la fonction publique
     territoriale dans les villes, policiers, gendarmes et militaires protégeant les
       citoyens, instituteurs, professeurs, chefs d'établissement instruisant nos
                                       enfants...
      Merci à vous tous pour votre engagement et votre solidarité dans cette crise
                                       sanitaire !

                                    À vous de choisir
                                    À vous de choisir

                   NATURE                  DIGITAL                 SANTÉ
                   SECURITÉ                PRÉVENTION              FAMILLE
                   ENVIRONNEMENT           SANTÉ                   ASSURANCE
                   DIGITAL                                         SOLIDARITÉ
                   PRÉVENTION


     juillet 2020                      25 août 2020                      18 septembre 2020

     Prix Hélioscope-GMF               Prix Chercheurs en                Prix Route 18
Avan                                   Actes
     Votez pour votre projet                                             Clôture des
     préféré jusqu'au 31               Cérémonie de remise du            candidatures pour le
     juillet.                          Prix Chercheurs en                Prix Route 18.
                                       Actes à la Sorbonne.

                                     Nous contacter
                                     Nous contacter

          Être rappelé                  Prendre RDV en ligne             Trouver l'agence proche
              Être                           Prendre RDV                      de chez vous
             rappelé                          en ligne                      Trouver l'agence
                                                                           proche de chez vous


     Accéder à votre  Accéder à         N'hésitez pas à visiter votre Espace GMF, pour
     Espace GMF       votre             profiter des bons plans et services exclusifs,
                      Espace GMF        consulter et gérer vos contrats d'assurances,
                                        services financiers et sinistres.


      GMF Assurément Humain   GMF 1er Assureur des Agents
                                   du Service Public

     Vous pouvez vous désinscrire en suivant ce lien.

     LA GARANTIE MUTUELLE DES FONCTIONNAIRES et employés de l'état et des services
     publics et assimilés. Société d'assurance mutuelle – Entreprise régie par le
     Code des assurances – RCS Paris 775691140 – Siège social : 148 rue
     Anatole-France, 92597 Levallois-Perret Cedex.
     GMF Assurances – Société anonyme au capital de 181 385 440 euros entièrement
     versé – Entreprise régie par le Code des assurances – RCS Nanterre 398 972 901
     – Siège social : 148 rue Anatole France, 92300 LEVALLOIS-PERRET.

[0]
 
1 members found this post helpful.
Old 07-10-2020, 05:03 PM   #9
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
Quote:
Originally Posted by Michael Uplawski View Post
I am not sure that I can then always identify the right file as file-names are allocated automatically.
Try the option --name-by-type.
 
Old 07-10-2020, 11:03 PM   #10
Michael Uplawski
Senior Member
 
Registered: Dec 2015
Posts: 1,621

Original Poster
Blog Entries: 40

Rep: Reputation: Disabled
Quote:
Originally Posted by shruggy View Post
This is my result
Code:
$  sed -n '/^<!/,/^<\/html>/p' gmfmail.eml.txt|qprint -d|w3m -dump -T text/html[color=green]
Thank you.

I'd rather (and exceptionally) use this call to sed and will try to define a macro. ripmime --name-by-type may be useful in different contexts, though.

Last edited by Michael Uplawski; 07-11-2020 at 01:17 AM. Reason: formating repaired.
 
Old 07-11-2020, 07:10 AM   #11
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
There may be differences in how HTML MIME parts are formatted though. The following sed expression will probably catch most variants:
Code:
sed -n '/<html\>/,/<\/html>/p'
There are also some duplicate lines that could be weeded out with uniq as the last step.

Last edited by shruggy; 07-11-2020 at 07:23 AM.
 
  


Reply

Tags
html-mail, html2text, mail to file, mutt



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] [Mutt] Can I process a current mail in a shell command from Mutt? Michael Uplawski Linux - Software 5 06-21-2016 02:56 AM
[SOLVED] Mutt does not change the "unread" flag on the IMAP server and other Mutt questions TobiSGD Linux - Software 1 10-09-2012 08:44 AM
mutt does not honour mutt.rc 'use_from' entry when accepting piped input davidchall Linux - Software 0 05-28-2012 02:13 AM
Mutt experts - Mutt won't use the Maildir I specify in .muttrc moistTowelette Debian 2 08-24-2009 08:04 AM
Mutt question: "How can I configure mutt for not automarking as read??" xowl Linux - Software 0 09-25-2007 09:09 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration