J'ai fait un script pour décoder les entêtes MIME selon le RFC 2047.
Je l'ai appelé decode2047 et je le joins à la fin de cet article.
Tests :
> om@kentia:~$ decode2047 "=?UTF-8?Q?Ceci_est_une_tentative_d'encoder_un_=5f_en_quoted-printab?= =?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?="
> Ceci est une tentative d'encoder un _ en quoted-printable (was: Hé etc.)
> om@kentia:~$ decode2047 "=?UTF-8?Q?Ceci_est_une_tentative_d'encoder_un_=5f_en_quoted-printab?= HELLO =?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?="
> Ceci est une tentative d'encoder un _ en quoted-printab HELLO le (was: Hé etc.)
Merci d'essayer pour voir si ça fonctionne aussi sur Mac (il faut les
commandes qprint et base64).
========================================================================
#!/bin/bash
# Script pour décoder un entête MIME
#
# Cette fonction vérifie que le paramètre est bien un encoded-word,
# puis elle le décode et le traduit en UTF-8.
#
# Si tout est OK, le résultat est dans $RESULT et la fonction retourne 0.
# Sinon, la fonction retourne 1.
#
decode_word()
{
# Un encoded-word doit être tout seul
if [ "$#" != "1" ]; then return 1; fi
# On vérifie que le paramètre est bien sous la forme :
# =?<charset>?<encoding>?<encoded>?=
# avec :
# <charset> : lettres, chiffres, underscores ou tirets
# <encoding> : B ou Q en majuscule ou minuscule
# <encoded> : ASCII imprimable sans espace ni point d'interrogation
if [ $(LANG=C expr "$1" : '=?[A-Za-z0-9_-]\+?[BbQq]?[!->@-~]\+?=$') = 0 ]
then
return 1;
fi
for word in $*
do
if decode_word "$word"
then
CURR_RETCODE=0
else
CURR_RETCODE=1
RESULT="$word"
fi
case "$PREV_RETCODE" in
0 )
# Previous string was an encoded-word.
# Add a space only if currect string is not.
if [ "$CURR_RETCODE" = "1" ]
then
RESULT=" ${RESULT}"
fi
;;
1 )
# Previous string was not an encoded-word.
# Always add a space.
RESULT=" ${RESULT}"
;;
* )
# There is no previous string.
# Never add a space.
;;
esac
PREV_RETCODE="$CURR_RETCODE"
Le 14 octobre 2019, Olivier Miakinen a pris le temps d'écrire :
Tu as un bash 3.2, de douze ans d'âge. C'est peut-être sympa pour un whisky, mais pour un shell c'est un peu ancien.
;-)
Bon, je vais tenter une alternative en passant par sed. Je mets ça au point dès que j'ai le temps, et je reviens.
Petite question : pourquoi tu fais tout ça ? C'est pour ta gouverne et c'est pour nous ? Parce qu'en fait, j'ai fabriqué, grâce notamment à nos discussions d'hier, un script AppleScript qui traite indifféremment les "?UTF-8?B", "?UTF-8?Q" et autre "?ISO-8859-1?Q". Bonne soirée. -- Michel VAUQUOIS - http://michelvauquois.fr
Le 14 octobre 2019, Olivier Miakinen a pris le temps d'écrire :
Tu as un bash 3.2, de douze ans d'âge. C'est peut-être sympa pour un
whisky, mais pour un shell c'est un peu ancien.
;-)
Bon, je vais tenter une alternative en passant par sed. Je mets ça
au point dès que j'ai le temps, et je reviens.
Petite question : pourquoi tu fais tout ça ? C'est pour ta gouverne
et c'est pour nous ?
Parce qu'en fait, j'ai fabriqué, grâce notamment à nos discussions
d'hier, un script AppleScript qui traite indifféremment les
"?UTF-8?B", "?UTF-8?Q" et autre "?ISO-8859-1?Q".
Bonne soirée.
--
Michel VAUQUOIS - http://michelvauquois.fr
Le 14 octobre 2019, Olivier Miakinen a pris le temps d'écrire :
Tu as un bash 3.2, de douze ans d'âge. C'est peut-être sympa pour un whisky, mais pour un shell c'est un peu ancien.
;-)
Bon, je vais tenter une alternative en passant par sed. Je mets ça au point dès que j'ai le temps, et je reviens.
Petite question : pourquoi tu fais tout ça ? C'est pour ta gouverne et c'est pour nous ? Parce qu'en fait, j'ai fabriqué, grâce notamment à nos discussions d'hier, un script AppleScript qui traite indifféremment les "?UTF-8?B", "?UTF-8?Q" et autre "?ISO-8859-1?Q". Bonne soirée. -- Michel VAUQUOIS - http://michelvauquois.fr
M.V.
Le 14 octobre 2019, Olivier Miakinen a pris le temps d'écrire :
La syntaxe « expr chaîne : regexp » ne fonctionne pas.
Mais "expr" est reconnu et voici le man : ********** MacBook-Air-MV:~ MV$ man expr EXAMPLES o The following example (in sh(1) syntax) adds one to the variable a: a=$(expr $a + 1) o This will fail if the value of a is a negative number. To protect negative values of a from being interpreted as options to the expr command, one might rearrange the expression: a=$(expr 1 + $a) o More generally, parenthesize possibly-negative values: a=$(expr ( $a ) + 1) o With shell arithmetic, no escaping is required: a=$((a + 1)) o This example prints the filename portion of a pathname stored in variable a. Since a might repre- sent the path /, it is necessary to prevent it from being interpreted as the division operator. The // characters resolve this ambiguity. expr "//$a" : '.*/(.*)' o With modern sh(1) syntax, "${a##*/}" expands to the same value. The following examples output the number of characters in variable a. Again, if a might begin with a hyphen, it is necessary to prevent it from being interpreted as an option to expr, and a might be interpreted as an operator. o To deal with all of this, a complicated command is required: expr ( "X$a" : ".*" ) - 1 o With modern sh(1) syntax, this can be done much more easily: ${#a} expands to the required number. SEE ALSO sh(1), test(1) STANDARDS The expr utility conforms to IEEE Std 1003.1-2008 (``POSIX.1''). The extended arithmetic range and overflow checks do not conflict with POSIX's requirement that arith- metic be done using signed longs, since they only make a difference to the result in cases where using signed longs would give undefined behavior. According to the POSIX standard, the use of string arguments length, substr, index, or match produces undefined results. In this version of expr, these arguments are treated just as their respective string values. BSD September 9, 2010 BSD (END) ********** Bonne soirée. -- Michel VAUQUOIS - http://michelvauquois.fr
Le 14 octobre 2019, Olivier Miakinen a pris le temps d'écrire :
La syntaxe « expr chaîne : regexp » ne
fonctionne pas.
Mais "expr" est reconnu et voici le man :
**********
MacBook-Air-MV:~ MV$ man expr
EXAMPLES
o The following example (in sh(1) syntax) adds one to the variable a:
a=$(expr $a + 1)
o This will fail if the value of a is a negative number. To protect negative values of a
from being
interpreted as options to the expr command, one might rearrange the expression:
a=$(expr 1 + $a)
o More generally, parenthesize possibly-negative values:
a=$(expr ( $a ) + 1)
o With shell arithmetic, no escaping is required:
a=$((a + 1))
o This example prints the filename portion of a pathname stored in variable a. Since a might
repre-
sent the path /, it is necessary to prevent it from being interpreted as the division
operator.
The // characters resolve this ambiguity.
expr "//$a" : '.*/(.*)'
o With modern sh(1) syntax,
"${a##*/}"
expands to the same value.
The following examples output the number of characters in variable a. Again, if a might begin
with a
hyphen, it is necessary to prevent it from being interpreted as an option to expr, and a might
be
interpreted as an operator.
o To deal with all of this, a complicated command is required:
expr ( "X$a" : ".*" ) - 1
o With modern sh(1) syntax, this can be done much more easily:
${#a}
expands to the required number.
SEE ALSO
sh(1), test(1)
STANDARDS
The expr utility conforms to IEEE Std 1003.1-2008 (``POSIX.1'').
The extended arithmetic range and overflow checks do not conflict with POSIX's requirement that
arith-
metic be done using signed longs, since they only make a difference to the result in cases
where using
signed longs would give undefined behavior.
According to the POSIX standard, the use of string arguments length, substr, index, or match
produces
undefined results. In this version of expr, these arguments are treated just as their
respective string
values.
BSD September 9, 2010 BSD
(END)
**********
Bonne soirée.
--
Michel VAUQUOIS - http://michelvauquois.fr
Le 14 octobre 2019, Olivier Miakinen a pris le temps d'écrire :
La syntaxe « expr chaîne : regexp » ne fonctionne pas.
Mais "expr" est reconnu et voici le man : ********** MacBook-Air-MV:~ MV$ man expr EXAMPLES o The following example (in sh(1) syntax) adds one to the variable a: a=$(expr $a + 1) o This will fail if the value of a is a negative number. To protect negative values of a from being interpreted as options to the expr command, one might rearrange the expression: a=$(expr 1 + $a) o More generally, parenthesize possibly-negative values: a=$(expr ( $a ) + 1) o With shell arithmetic, no escaping is required: a=$((a + 1)) o This example prints the filename portion of a pathname stored in variable a. Since a might repre- sent the path /, it is necessary to prevent it from being interpreted as the division operator. The // characters resolve this ambiguity. expr "//$a" : '.*/(.*)' o With modern sh(1) syntax, "${a##*/}" expands to the same value. The following examples output the number of characters in variable a. Again, if a might begin with a hyphen, it is necessary to prevent it from being interpreted as an option to expr, and a might be interpreted as an operator. o To deal with all of this, a complicated command is required: expr ( "X$a" : ".*" ) - 1 o With modern sh(1) syntax, this can be done much more easily: ${#a} expands to the required number. SEE ALSO sh(1), test(1) STANDARDS The expr utility conforms to IEEE Std 1003.1-2008 (``POSIX.1''). The extended arithmetic range and overflow checks do not conflict with POSIX's requirement that arith- metic be done using signed longs, since they only make a difference to the result in cases where using signed longs would give undefined behavior. According to the POSIX standard, the use of string arguments length, substr, index, or match produces undefined results. In this version of expr, these arguments are treated just as their respective string values. BSD September 9, 2010 BSD (END) ********** Bonne soirée. -- Michel VAUQUOIS - http://michelvauquois.fr
M.V.
Le 14 octobre 2019, M.V. a pris le temps d'écrire :
Mais "expr" est reconnu et voici le man
Il y a ça aussi : <https://ss64.com/osx/expr.html> Bonne soirée. -- Michel VAUQUOIS - http://michelvauquois.fr
Le 14 octobre 2019, M.V. a pris le temps d'écrire :
Mais "expr" est reconnu et voici le man
Il y a ça aussi : <https://ss64.com/osx/expr.html>
Bonne soirée.
--
Michel VAUQUOIS - http://michelvauquois.fr
Le 14 octobre 2019, M.V. a pris le temps d'écrire :
Mais "expr" est reconnu et voici le man
Il y a ça aussi : <https://ss64.com/osx/expr.html> Bonne soirée. -- Michel VAUQUOIS - http://michelvauquois.fr
Olivier Miakinen
Le 14/10/2019 à 16:38, M.V. a écrit :
Le 14 octobre 2019, M.V. a pris le temps d'écrire :
Mais "expr" est reconnu et voici le man
Il y a ça aussi : <https://ss64.com/osx/expr.html>
<cit. https://ss64.com/osx/expr.html> expr expects "basic" regular expressions, see re_format(7) for more informa- tion on regular expressions. </cit.> <cit. http://www.manpagez.com/man/7/re_format/> `+' and `?' are ordinary characters, and their functionality can be expressed using bounds (`{1,}' or `{0,1}' respectively). </cit.> Du coup, essaye de remplacer : =?[A-Za-z0-9_-]+?[BbQq]?[!->@-~]+?=$ par : =?[A-Za-z0-9_-]{1,}?[BbQq]?[!->@-~]{1,}?=$ -- Olivier Miakinen
Le 14/10/2019 à 16:38, M.V. a écrit :
Le 14 octobre 2019, M.V. a pris le temps d'écrire :
Mais "expr" est reconnu et voici le man
Il y a ça aussi : <https://ss64.com/osx/expr.html>
<cit. https://ss64.com/osx/expr.html>
expr expects
"basic" regular expressions, see re_format(7) for more informa-
tion on regular expressions.
</cit.>
<cit. http://www.manpagez.com/man/7/re_format/>
`+' and `?' are ordinary characters, and their functionality can be
expressed using bounds (`{1,}' or `{0,1}' respectively).
</cit.>
Du coup, essaye de remplacer :
=?[A-Za-z0-9_-]+?[BbQq]?[!->@-~]+?=$
par :
=?[A-Za-z0-9_-]{1,}?[BbQq]?[!->@-~]{1,}?=$
Le 14 octobre 2019, M.V. a pris le temps d'écrire :
Mais "expr" est reconnu et voici le man
Il y a ça aussi : <https://ss64.com/osx/expr.html>
<cit. https://ss64.com/osx/expr.html> expr expects "basic" regular expressions, see re_format(7) for more informa- tion on regular expressions. </cit.> <cit. http://www.manpagez.com/man/7/re_format/> `+' and `?' are ordinary characters, and their functionality can be expressed using bounds (`{1,}' or `{0,1}' respectively). </cit.> Du coup, essaye de remplacer : =?[A-Za-z0-9_-]+?[BbQq]?[!->@-~]+?=$ par : =?[A-Za-z0-9_-]{1,}?[BbQq]?[!->@-~]{1,}?=$ -- Olivier Miakinen
Olivier Miakinen
Le 14/10/2019 à 16:58, je répondais à M.V. :
Du coup, essaye de remplacer : =?[A-Za-z0-9_-]+?[BbQq]?[!->@-~]+?=$ par : =?[A-Za-z0-9_-]{1,}?[BbQq]?[!->@-~]{1,}?=$
Et si ça ne fonctionne pas : =?[A-Za-z0-9_-]*?[BbQq]?[!->@-~]*?=$ -- Olivier Miakinen
Le 14/10/2019 à 16:58, je répondais à M.V. :
Du coup, essaye de remplacer :
=?[A-Za-z0-9_-]+?[BbQq]?[!->@-~]+?=$
par :
=?[A-Za-z0-9_-]{1,}?[BbQq]?[!->@-~]{1,}?=$
Et si ça ne fonctionne pas :
=?[A-Za-z0-9_-]*?[BbQq]?[!->@-~]*?=$
Du coup, essaye de remplacer : =?[A-Za-z0-9_-]+?[BbQq]?[!->@-~]+?=$ par : =?[A-Za-z0-9_-]{1,}?[BbQq]?[!->@-~]{1,}?=$
Et si ça ne fonctionne pas : =?[A-Za-z0-9_-]*?[BbQq]?[!->@-~]*?=$ -- Olivier Miakinen
Olivier Miakinen
Le 14/10/2019 à 16:19, M.V. a écrit :
Petite question : pourquoi tu fais tout ça ? C'est pour ta gouverne et c'est pour nous ?
C'est pour ma propre gouverne en premier lieu, pour la satisfaction de rendre service ensuite. C'est aussi pour montrer comment gérer le cas de plusieurs chaînes dans le même entête, selon qu'elles sont toutes des encoded-word ou non.
Parce qu'en fait, j'ai fabriqué, grâce notamment à nos discussions d'hier, un script AppleScript qui traite indifféremment les "?UTF-8?B", "?UTF-8?Q" et autre "?ISO-8859-1?Q".
Ok, mais sais-tu aussi gérer les "?ISO-8859-1?B", "utf8?b" et "?wiNdoWs-1252?Q" ? En principe iconv sait faire tout ça. -- Olivier Miakinen
Le 14/10/2019 à 16:19, M.V. a écrit :
Petite question : pourquoi tu fais tout ça ? C'est pour ta gouverne
et c'est pour nous ?
C'est pour ma propre gouverne en premier lieu, pour la satisfaction
de rendre service ensuite. C'est aussi pour montrer comment gérer
le cas de plusieurs chaînes dans le même entête, selon qu'elles
sont toutes des encoded-word ou non.
Parce qu'en fait, j'ai fabriqué, grâce notamment à nos discussions
d'hier, un script AppleScript qui traite indifféremment les
"?UTF-8?B", "?UTF-8?Q" et autre "?ISO-8859-1?Q".
Ok, mais sais-tu aussi gérer les "?ISO-8859-1?B", "utf8?b" et
"?wiNdoWs-1252?Q" ? En principe iconv sait faire tout ça.
Petite question : pourquoi tu fais tout ça ? C'est pour ta gouverne et c'est pour nous ?
C'est pour ma propre gouverne en premier lieu, pour la satisfaction de rendre service ensuite. C'est aussi pour montrer comment gérer le cas de plusieurs chaînes dans le même entête, selon qu'elles sont toutes des encoded-word ou non.
Parce qu'en fait, j'ai fabriqué, grâce notamment à nos discussions d'hier, un script AppleScript qui traite indifféremment les "?UTF-8?B", "?UTF-8?Q" et autre "?ISO-8859-1?Q".
Ok, mais sais-tu aussi gérer les "?ISO-8859-1?B", "utf8?b" et "?wiNdoWs-1252?Q" ? En principe iconv sait faire tout ça. -- Olivier Miakinen
M.V.
Le 14 octobre 2019, Olivier Miakinen a pris le temps d'écrire :
Du coup, essaye de remplacer : =?[A-Za-z0-9_-]+?[BbQq]?[!->@-~]+?=$ par : =?[A-Za-z0-9_-]{1,}?[BbQq]?[!->@-~]{1,}?=$
Et si ça ne fonctionne pas : =?[A-Za-z0-9_-]*?[BbQq]?[!->@-~]*?=$
Marche pas non plus : ********** ~/olivier.sh "=?UTF-8?Q?Ceci_est_une_tentative_d'encoder_un___en_quoted-printab?= =?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?=" + '[' 1 '!=' 1 ']' ++ LANG=C ++ expr '=?UTF-8?Q?Ceci_est_une_tentative_d'''encoder_un___en_quoted-printab?=' : '=?[A-Za-z0-9_-]*?[BbQq]?[!->@-~]*?=$' + '[' 69 = 0 ']' ++ printf '=?UTF-8?Q?Ceci_est_une_tentative_d'''encoder_un___en_quoted-printab?=' ++ cut -f 2 -d '?' + charset=UTF-8 ++ printf '=?UTF-8?Q?Ceci_est_une_tentative_d'''encoder_un___en_quoted-printab?=' ++ cut -f 3 -d '?' + encoding=Q ++ printf '=?UTF-8?Q?Ceci_est_une_tentative_d'''encoder_un___en_quoted-printab?=' ++ cut -f 4 -d '?' + encoded='Ceci_est_une_tentative_d'''encoder_un___en_quoted-printab' + case $encoding in ++ printf 'Ceci_est_une_tentative_d'''encoder_un___en_quoted-printab' ++ tr _ ' ' ++ qprint -d + decoded='Ceci est une tentative d'''encoder un _ en quoted-printab' + '[' 0 '!=' 0 ']' ++ printf 'Ceci est une tentative d'''encoder un _ en quoted-printab' ++ iconv -f UTF-8 -t UTF-8 + RESULT='Ceci est une tentative d'''encoder un _ en quoted-printab' + return 0 + CURR_RETCODE=0 + case "$PREV_RETCODE" in + PREV_RETCODE=0 + FINAL_RESULT='Ceci est une tentative d'''encoder un _ en quoted-printab' + for word in '$*' + decode_word '=?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?=' + set -x + '[' 1 '!=' 1 ']' ++ LANG=C ++ expr '=?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?=' : '=?[A-Za-z0-9_-]*?[BbQq]?[!->@-~]*?=$' + '[' 36 = 0 ']' ++ printf '=?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?=' ++ cut -f 2 -d '?' + charset=UTF-8 ++ printf '=?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?=' ++ cut -f 3 -d '?' + encoding=B ++ printf '=?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?=' ++ cut -f 4 -d '?' + encoded=bGUgKHdhczogSMOpIGV0Yy4p + case $encoding in ++ printf bGUgKHdhczogSMOpIGV0Yy4p ++ base64 -d + decoded + '[' 64 '!=' 0 ']' + return 1 + CURR_RETCODE=1 + RESULT='=?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?=' + case "$PREV_RETCODE" in + '[' 1 = 1 ']' + RESULT=' =?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?=' + PREV_RETCODE=1 + FINAL_RESULT='Ceci est une tentative d'''encoder un _ en quoted-printab =?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?=' + echo 'Ceci est une tentative d'''encoder un _ en quoted-printab =?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?=' Ceci est une tentative d'encoder un _ en quoted-printab =?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p? ********** Mais dans le 2ème cas, ça me semble parfait pour la 1ère partie à décoder mais le décodage de la 2ème ne se fait pas. Bonne soirée. -- Michel VAUQUOIS - http://michelvauquois.fr
M.V.
Le 14 octobre 2019, Olivier Miakinen a pris le temps d'écrire :
k, mais sais-tu aussi gérer les "?ISO-8859-1?B", "utf8?b" et "?wiNdoWs-1252?Q" ? En principe iconv sait faire tout ça.
Faudrait que l'occasion de rencontrer ce genre de charset se présente et je les incluerai dans mon script si tu me dis que iconv sait gérer ça (d'après "iconv -l" qui donne la liste des charsets valides, ça devrait). Bonne soirée. -- Michel VAUQUOIS - http://michelvauquois.fr
Le 14 octobre 2019, Olivier Miakinen a pris le temps d'écrire :
k, mais sais-tu aussi gérer les "?ISO-8859-1?B", "utf8?b" et
"?wiNdoWs-1252?Q" ? En principe iconv sait faire tout ça.
Faudrait que l'occasion de rencontrer ce genre de charset se présente
et je les incluerai dans mon script si tu me dis que iconv sait gérer
ça (d'après "iconv -l" qui donne la liste des charsets valides, ça
devrait).
Bonne soirée.
--
Michel VAUQUOIS - http://michelvauquois.fr
Le 14 octobre 2019, Olivier Miakinen a pris le temps d'écrire :
k, mais sais-tu aussi gérer les "?ISO-8859-1?B", "utf8?b" et "?wiNdoWs-1252?Q" ? En principe iconv sait faire tout ça.
Faudrait que l'occasion de rencontrer ce genre de charset se présente et je les incluerai dans mon script si tu me dis que iconv sait gérer ça (d'après "iconv -l" qui donne la liste des charsets valides, ça devrait). Bonne soirée. -- Michel VAUQUOIS - http://michelvauquois.fr
M.V.
Le 14 octobre 2019, Olivier Miakinen a pris le temps d'écrire :
Et si ça ne fonctionne pas : =?[A-Za-z0-9_-]*?[BbQq]?[!->@-~]*?=$
Avec la 1ère chaîne de caractères, ça marche effectivement très bien : ********** ~/olivier.sh "=?UTF-8?Q?Ceci_est_une_tentative_d'encoder_un___en_quoted-printab?=" Ceci est une tentative d'encoder un _ en quoted-printab ********** NB J'ai viré le "set -x" que tu m'avais fait rajouter cet après-midi. Mais avec la 2ème, ça foire : ********** ~/olivier.sh "=?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?=" =?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p? ********** Avec le détail, ça donne ça : ********** ~/olivier.sh "=?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?=" + '[' 1 '!=' 1 ']' ++ LANG=C ++ expr '=?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?=' : '=?[A-Za-z0-9_-]*?[BbQq]?[!->@-~]*?=$' + '[' 36 = 0 ']' ++ printf '=?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?=' ++ cut -f 2 -d '?' + charset=UTF-8 ++ printf '=?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?=' ++ cut -f 3 -d '?' + encoding=B ++ printf '=?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?=' ++ cut -f 4 -d '?' + encoded=bGUgKHdhczogSMOpIGV0Yy4p + case $encoding in ++ printf bGUgKHdhczogSMOpIGV0Yy4p ++ base64 -d + decoded + '[' 64 '!=' 0 ']' + return 1 + CURR_RETCODE=1 + RESULT='=?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?=' + case "$PREV_RETCODE" in + PREV_RETCODE=1 + FINAL_RESULT='=?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?=' + echo '=?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?=' =?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p? ********** Bonne soirée. -- Michel VAUQUOIS - http://michelvauquois.fr
Le 14 octobre 2019, Olivier Miakinen a pris le temps d'écrire :
Et si ça ne fonctionne pas :
=?[A-Za-z0-9_-]*?[BbQq]?[!->@-~]*?=$
Avec la 1ère chaîne de caractères, ça marche effectivement très bien :
**********
~/olivier.sh "=?UTF-8?Q?Ceci_est_une_tentative_d'encoder_un___en_quoted-printab?="
Ceci est une tentative d'encoder un _ en quoted-printab
**********
NB J'ai viré le "set -x" que tu m'avais fait rajouter cet après-midi.
Et si ça ne fonctionne pas : =?[A-Za-z0-9_-]*?[BbQq]?[!->@-~]*?=$
Marche pas non plus : ********** ~/olivier.sh "=?UTF-8?Q?Ceci_est_une_tentative_d'encoder_un___en_quoted-printab?= =?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?=" + '[' 1 '!=' 1 ']' ++ LANG=C ++ expr '=?UTF-8?Q?Ceci_est_une_tentative_d'''encoder_un___en_quoted-printab?=' : '=?[A-Za-z0-9_-]*?[BbQq]?[!->@-~]*?=$' + '[' 69 = 0 ']'
Pourtant jusqu'ici ça fonctionne.
++ printf '=?UTF-8?Q?Ceci_est_une_tentative_d'''encoder_un___en_quoted-printab?=' ++ cut -f 2 -d '?' + charset=UTF-8 ++ printf '=?UTF-8?Q?Ceci_est_une_tentative_d'''encoder_un___en_quoted-printab?=' ++ cut -f 3 -d '?' + encoding=Q ++ printf '=?UTF-8?Q?Ceci_est_une_tentative_d'''encoder_un___en_quoted-printab?=' ++ cut -f 4 -d '?' + encoded='Ceci_est_une_tentative_d'''encoder_un___en_quoted-printab' + case $encoding in ++ printf 'Ceci_est_une_tentative_d'''encoder_un___en_quoted-printab' ++ tr _ ' ' ++ qprint -d + decoded='Ceci est une tentative d'''encoder un _ en quoted-printab' + '[' 0 '!=' 0 ']' ++ printf 'Ceci est une tentative d'''encoder un _ en quoted-printab' ++ iconv -f UTF-8 -t UTF-8 + RESULT='Ceci est une tentative d'''encoder un _ en quoted-printab' + return 0
Ça a même fonctionné jusqu'au bout pour la première chaîne.
+ CURR_RETCODE=0 + case "$PREV_RETCODE" in + PREV_RETCODE=0 + FINAL_RESULT='Ceci est une tentative d'''encoder un _ en quoted-printab' + for word in '$*' + decode_word '=?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?=' + set -x + '[' 1 '!=' 1 ']' ++ LANG=C ++ expr '=?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?=' : '=?[A-Za-z0-9_-]*?[BbQq]?[!->@-~]*?=$' + '[' 36 = 0 ']'
C'est le décodage par base64 qui n'a pas fonctionné. Tu as bien installé le programme ? Et est-ce qu'on l'appelle bien avec « base64 -d » ?
+ CURR_RETCODE=1 + RESULT='=?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?=' + case "$PREV_RETCODE" in + '[' 1 = 1 ']' + RESULT=' =?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?=' + PREV_RETCODE=1 + FINAL_RESULT='Ceci est une tentative d'''encoder un _ en quoted-printab =?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?=' + echo 'Ceci est une tentative d'''encoder un _ en quoted-printab =?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?=' Ceci est une tentative d'encoder un _ en quoted-printab =?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p? > ********** Mais dans le 2ème cas, ça me semble parfait pour la 1ère partie à décoder mais le décodage de la 2ème ne se fait pas.
Oui. Le qprint a fonctionné mais pas le base64. -- Olivier Miakinen
Le 14/10/2019 à 17:30, M.V. a écrit :
Le 14 octobre 2019, Olivier Miakinen a pris le temps d'écrire :
Du coup, essaye de remplacer :
=?[A-Za-z0-9_-]+?[BbQq]?[!->@-~]+?=$
par :
=?[A-Za-z0-9_-]{1,}?[BbQq]?[!->@-~]{1,}?=$
Et si ça ne fonctionne pas :
=?[A-Za-z0-9_-]*?[BbQq]?[!->@-~]*?=$
Marche pas non plus :
**********
~/olivier.sh "=?UTF-8?Q?Ceci_est_une_tentative_d'encoder_un___en_quoted-printab?= =?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?="
+ '[' 1 '!=' 1 ']'
++ LANG=C
++ expr '=?UTF-8?Q?Ceci_est_une_tentative_d'''encoder_un___en_quoted-printab?=' : '=?[A-Za-z0-9_-]*?[BbQq]?[!->@-~]*?=$'
+ '[' 69 = 0 ']'
Pourtant jusqu'ici ça fonctionne.
++ printf '=?UTF-8?Q?Ceci_est_une_tentative_d'''encoder_un___en_quoted-printab?='
++ cut -f 2 -d '?'
+ charset=UTF-8
++ printf '=?UTF-8?Q?Ceci_est_une_tentative_d'''encoder_un___en_quoted-printab?='
++ cut -f 3 -d '?'
+ encoding=Q
++ printf '=?UTF-8?Q?Ceci_est_une_tentative_d'''encoder_un___en_quoted-printab?='
++ cut -f 4 -d '?'
+ encoded='Ceci_est_une_tentative_d'''encoder_un___en_quoted-printab'
+ case $encoding in
++ printf 'Ceci_est_une_tentative_d'''encoder_un___en_quoted-printab'
++ tr _ ' '
++ qprint -d
+ decoded='Ceci est une tentative d'''encoder un _ en quoted-printab'
+ '[' 0 '!=' 0 ']'
++ printf 'Ceci est une tentative d'''encoder un _ en quoted-printab'
++ iconv -f UTF-8 -t UTF-8
+ RESULT='Ceci est une tentative d'''encoder un _ en quoted-printab'
+ return 0
Ça a même fonctionné jusqu'au bout pour la première chaîne.
+ CURR_RETCODE=0
+ case "$PREV_RETCODE" in
+ PREV_RETCODE=0
+ FINAL_RESULT='Ceci est une tentative d'''encoder un _ en quoted-printab'
+ for word in '$*'
+ decode_word '=?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?='
+ set -x
+ '[' 1 '!=' 1 ']'
++ LANG=C
++ expr '=?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?=' : '=?[A-Za-z0-9_-]*?[BbQq]?[!->@-~]*?=$'
+ '[' 36 = 0 ']'
C'est le décodage par base64 qui n'a pas fonctionné. Tu as bien installé
le programme ? Et est-ce qu'on l'appelle bien avec « base64 -d » ?
+ CURR_RETCODE=1
+ RESULT='=?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?='
+ case "$PREV_RETCODE" in
+ '[' 1 = 1 ']'
+ RESULT=' =?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?='
+ PREV_RETCODE=1
+ FINAL_RESULT='Ceci est une tentative d'''encoder un _ en quoted-printab =?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?='
+ echo 'Ceci est une tentative d'''encoder un _ en quoted-printab =?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?='
Ceci est une tentative d'encoder un _ en quoted-printab =?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p? > **********
Mais dans le 2ème cas, ça me semble parfait pour la 1ère partie à
décoder mais le décodage de la 2ème ne se fait pas.
Et si ça ne fonctionne pas : =?[A-Za-z0-9_-]*?[BbQq]?[!->@-~]*?=$
Marche pas non plus : ********** ~/olivier.sh "=?UTF-8?Q?Ceci_est_une_tentative_d'encoder_un___en_quoted-printab?= =?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?=" + '[' 1 '!=' 1 ']' ++ LANG=C ++ expr '=?UTF-8?Q?Ceci_est_une_tentative_d'''encoder_un___en_quoted-printab?=' : '=?[A-Za-z0-9_-]*?[BbQq]?[!->@-~]*?=$' + '[' 69 = 0 ']'
Pourtant jusqu'ici ça fonctionne.
++ printf '=?UTF-8?Q?Ceci_est_une_tentative_d'''encoder_un___en_quoted-printab?=' ++ cut -f 2 -d '?' + charset=UTF-8 ++ printf '=?UTF-8?Q?Ceci_est_une_tentative_d'''encoder_un___en_quoted-printab?=' ++ cut -f 3 -d '?' + encoding=Q ++ printf '=?UTF-8?Q?Ceci_est_une_tentative_d'''encoder_un___en_quoted-printab?=' ++ cut -f 4 -d '?' + encoded='Ceci_est_une_tentative_d'''encoder_un___en_quoted-printab' + case $encoding in ++ printf 'Ceci_est_une_tentative_d'''encoder_un___en_quoted-printab' ++ tr _ ' ' ++ qprint -d + decoded='Ceci est une tentative d'''encoder un _ en quoted-printab' + '[' 0 '!=' 0 ']' ++ printf 'Ceci est une tentative d'''encoder un _ en quoted-printab' ++ iconv -f UTF-8 -t UTF-8 + RESULT='Ceci est une tentative d'''encoder un _ en quoted-printab' + return 0
Ça a même fonctionné jusqu'au bout pour la première chaîne.
+ CURR_RETCODE=0 + case "$PREV_RETCODE" in + PREV_RETCODE=0 + FINAL_RESULT='Ceci est une tentative d'''encoder un _ en quoted-printab' + for word in '$*' + decode_word '=?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?=' + set -x + '[' 1 '!=' 1 ']' ++ LANG=C ++ expr '=?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?=' : '=?[A-Za-z0-9_-]*?[BbQq]?[!->@-~]*?=$' + '[' 36 = 0 ']'
C'est le décodage par base64 qui n'a pas fonctionné. Tu as bien installé le programme ? Et est-ce qu'on l'appelle bien avec « base64 -d » ?
+ CURR_RETCODE=1 + RESULT='=?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?=' + case "$PREV_RETCODE" in + '[' 1 = 1 ']' + RESULT=' =?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?=' + PREV_RETCODE=1 + FINAL_RESULT='Ceci est une tentative d'''encoder un _ en quoted-printab =?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?=' + echo 'Ceci est une tentative d'''encoder un _ en quoted-printab =?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p?=' Ceci est une tentative d'encoder un _ en quoted-printab =?UTF-8?B?bGUgKHdhczogSMOpIGV0Yy4p? > ********** Mais dans le 2ème cas, ça me semble parfait pour la 1ère partie à décoder mais le décodage de la 2ème ne se fait pas.
Oui. Le qprint a fonctionné mais pas le base64. -- Olivier Miakinen