-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tweak: python/imap-exemples-concrets + python/imaplib-suppression-des…
…-doublons
- Loading branch information
Showing
6 changed files
with
150 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ _build/ | |
_live/ | ||
luma/ | ||
.mypy_cache/ | ||
__pycache__/ | ||
.ruff_cache/ | ||
venv/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,101 @@ | ||
# Python et IMAP : Suppression des doublons | ||
|
||
Commençons par nous connecter à la boîte de messagerie : | ||
Script utile pour supprimer les messages en double/triple voire plus. | ||
|
||
```{todo} | ||
Supprimer les commentaires `type: ignore[…]` et corriger/retester le code. | ||
``` | ||
## 🎩 Le Script | ||
|
||
```{literalinclude} snippets/imaplib-suppression-des-doublons.py | ||
:caption: imap-delete-duplicate.py | ||
:lines: 1-124 | ||
:caption: imap-delete-duplicates.py | ||
:language: python | ||
``` | ||
|
||
## 📺 Utilisation | ||
|
||
Et voici ce que ça donne en situation réelle : | ||
|
||
```{code-block} text | ||
:caption: $ python imap-delete-duplicate.py 'mail.gandi.net' '[email protected]' | ||
```{code-block} shell | ||
python imap-delete-duplicates.py 'mail.gandi.net' '[email protected]' | ||
``` | ||
|
||
```{code-block} text | ||
:caption: Exemple de sortie | ||
Password: | ||
Drafts | ||
Trash | ||
>>> Drafts | ||
>>> Trash | ||
45 messages | ||
Sent | ||
>>> Sent | ||
37 messages | ||
1 doublons | ||
INBOX | ||
>>> INBOX | ||
888 messages | ||
443 doublons | ||
INBOX/Droit du travail | ||
>>> INBOX/Droit du travail | ||
2 messages | ||
``` | ||
|
||
Et avec une grosse boîte de messagerie : | ||
Et avec une boîte de messagerie contenant plusieurs dizaines de millers de messages : | ||
|
||
```{code-block} text | ||
:caption: $ time python imap-delete-duplicate.py 'imap.gmail.com' '[email protected]' | ||
```{code-block} shell | ||
time python imap-delete-duplicates.py 'imap.gmail.com' '[email protected]' | ||
``` | ||
|
||
```{code-block} text | ||
:caption: Exemple de sortie | ||
Password: | ||
Archives | ||
>>> Archives | ||
10792 messages | ||
9 doublons | ||
INBOX | ||
>>> INBOX | ||
6550 messages | ||
3 doublons | ||
Personnel | ||
>>> Personnel | ||
4 messages | ||
Re&AOc-us | ||
[Gmail]/Billetterie | ||
>>> Re&AOc-us | ||
>>> [Gmail]/Billetterie | ||
36 messages | ||
[Gmail]/Brouillons | ||
[Gmail]/Clef GNUPG | ||
[Gmail]/Corbeille | ||
>>> [Gmail]/Brouillons | ||
>>> [Gmail]/Clef GNUPG | ||
>>> [Gmail]/Corbeille | ||
37 messages | ||
[Gmail]/Important | ||
>>> [Gmail]/Important | ||
6153 messages | ||
2 doublons | ||
[Gmail]/Messages envoy&AOk-s | ||
>>> [Gmail]/Messages envoy&AOk-s | ||
8684 messages | ||
[Gmail]/Spam | ||
>>> [Gmail]/Spam | ||
1169 messages | ||
[Gmail]/Suivis | ||
>>> [Gmail]/Suivis | ||
22 messages | ||
[Gmail]/Tous les messages | ||
>>> [Gmail]/Tous les messages | ||
25970 messages | ||
12 doublons | ||
8,64s user 0,16s system 7% cpu 1:55,36 total | ||
``` | ||
|
||
````{note} | ||
Pour ajouter le bon Message-ID aux courriels envoyés par les functions du module {py:mod}`smtplib` de Python : | ||
## 📧 Message-ID | ||
|
||
```{literalinclude} snippets/imaplib-suppression-des-doublons.py | ||
:lines: 129-130 | ||
:dedent: | ||
:language: python | ||
Parfois, un message n'aura pas le Message-ID dans ses entêtes. Assuez-vous d'utiliser ces morceaux de code lorsque vous envoyez des courriels. | ||
|
||
### 🐍 Python | ||
|
||
Pour ajouter le bon Message-ID aux courriels envoyés par les functions du module {py:mod}`smtplib` : | ||
|
||
```{code-block} python | ||
from email.utils import make_msgid | ||
msg["Message-ID"] = make_msgid() | ||
``` | ||
```` | ||
|
||
````{note} | ||
Pour ajouter le bon Message-ID aux courriels envoyés par la fonction [`mail()`](https://www.php.net/manual/function.mail.php) de PHP : | ||
### 🐘 PHP | ||
|
||
Pour ajouter le bon Message-ID aux courriels envoyés par la fonction [`mail()`](https://www.php.net/manual/function.mail.php) : | ||
|
||
```{literalinclude} snippets/imaplib-suppression-des-doublons.php | ||
:lines: 2- | ||
:dedent: | ||
:language: php | ||
``` | ||
```` | ||
|
||
--- | ||
|
||
|
@@ -96,6 +105,10 @@ Pour ajouter le bon Message-ID aux courriels envoyés par la fonction [`mail()`] | |
|
||
## 📜 Historique | ||
|
||
2024-10-29 | ||
: Revue de code pour supprimer les commentaires `type: ignore[…]`, moderniser, et corriger/retester l'ensemble'. | ||
: Ajout des sections. | ||
|
||
2024-02-01 | ||
: Déplacement de l'article depuis le [blog](https://www.tiger-222.fr/?d=2016/02/05/18/00/41-imaplib-suppression-des-doublons). | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters