myl 0.8.9__py3-none-any.whl → 0.8.11__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: myl
3
- Version: 0.8.9
3
+ Version: 0.8.11
4
4
  Summary: Dead simple IMAP CLI client
5
5
  Author-email: Philipp Schmitt <philipp@schmitt.co>
6
6
  License: GNU GENERAL PUBLIC LICENSE
@@ -690,6 +690,7 @@ License-File: LICENSE
690
690
  Requires-Dist: imap-tools <2.0.0,>=1.5.0
691
691
  Requires-Dist: myl-discovery >=0.6.0
692
692
  Requires-Dist: rich <14.0.0,>=13.0.0
693
+ Requires-Dist: html2text >=2024.2.26
693
694
 
694
695
  # 📧 myl
695
696
 
@@ -0,0 +1,7 @@
1
+ myl.py,sha256=1TZZLxqXVr6YMo5q60n8KYxiLI1uColJp_IItPtAM10,10170
2
+ myl-0.8.11.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
3
+ myl-0.8.11.dist-info/METADATA,sha256=-PtYBX_cOR3oTgRq6sNRlQub4BcO9-SITZGqWBOcFgo,43318
4
+ myl-0.8.11.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
5
+ myl-0.8.11.dist-info/entry_points.txt,sha256=q6nr0Kzim7JzreXQE3BTU4asLh2sx5-D0w1yLBOcHxc,33
6
+ myl-0.8.11.dist-info/top_level.txt,sha256=Wn88OJVVWyYSsKVoqzlHXxfFxh5IbrJ_Yw-ldNLe7Po,4
7
+ myl-0.8.11.dist-info/RECORD,,
myl.py CHANGED
@@ -1,11 +1,16 @@
1
+ #!/usr/bin/env python3
2
+ # coding: utf-8
3
+
1
4
  import argparse
5
+ import html2text
6
+ import json
2
7
  import logging
3
8
  import ssl
4
9
  import sys
5
10
 
6
11
  import imap_tools
7
12
  from myldiscovery import autodiscover
8
- from rich import print
13
+ from rich import print, print_json
9
14
  from rich.console import Console
10
15
  from rich.logging import RichHandler
11
16
  from rich.table import Table
@@ -82,6 +87,13 @@ def parse_args():
82
87
  )
83
88
  parser.add_argument("-S", "--search", help="Search string", default="ALL")
84
89
  parser.add_argument("-H", "--html", help="Show HTML", action="store_true")
90
+ parser.add_argument(
91
+ "-j",
92
+ "--json",
93
+ help="JSON output",
94
+ action="store_true",
95
+ default=False,
96
+ )
85
97
  parser.add_argument(
86
98
  "-r",
87
99
  "--raw",
@@ -146,6 +158,7 @@ def main():
146
158
  )
147
159
  return 2
148
160
 
161
+ json_data = []
149
162
  table = Table(
150
163
  show_header=not args.no_title,
151
164
  header_style="bold",
@@ -200,7 +213,38 @@ def main():
200
213
  if args.raw:
201
214
  print(msg.obj.as_string())
202
215
  return 0
203
- print(msg.text if not args.html else msg.html)
216
+ elif args.json:
217
+ print_json(
218
+ json.dumps(
219
+ {
220
+ "uid": msg.uid,
221
+ "subject": msg.subject,
222
+ "from": msg.from_,
223
+ "to": msg.to,
224
+ "date": msg.date.strftime(
225
+ "%Y-%m-%d %H:%M:%S"
226
+ ),
227
+ "timestamp": str(
228
+ int(msg.date.timestamp())
229
+ ),
230
+ "content": {
231
+ "raw": msg.obj.as_string(),
232
+ "html": msg.html,
233
+ "text": msg.text,
234
+ },
235
+ "attachments": msg.attachments,
236
+ }
237
+ )
238
+ )
239
+ return 0
240
+
241
+ output = msg.text
242
+ if args.html:
243
+ if args.raw:
244
+ output = msg.html
245
+ else:
246
+ output = html2text.html2text(msg.html)
247
+ print(output)
204
248
  for att in msg.attachments:
205
249
  print(
206
250
  f"📎 Attachment: {att.filename}", file=sys.stderr
@@ -221,16 +265,41 @@ def main():
221
265
  if msg.subject
222
266
  else "<no-subject>"
223
267
  )
224
- table.add_row(
225
- msg.uid if msg.uid else "???",
226
- f"{subj_prefix}{subject}",
227
- msg.from_,
228
- msg.date.strftime("%H:%M %d/%m/%Y") if msg.date else "???",
229
- )
268
+ if args.json:
269
+ json_data.append(
270
+ {
271
+ "uid": msg.uid,
272
+ "subject": msg.subject,
273
+ "from": msg.from_,
274
+ "to": msg.to,
275
+ "date": msg.date.strftime("%Y-%m-%d %H:%M:%S"),
276
+ "timestamp": str(int(msg.date.timestamp())),
277
+ "content": {
278
+ "raw": msg.obj.as_string(),
279
+ "html": msg.html,
280
+ "text": msg.text,
281
+ },
282
+ "attachments": msg.attachments,
283
+ }
284
+ )
285
+ else:
286
+ table.add_row(
287
+ msg.uid if msg.uid else "???",
288
+ f"{subj_prefix}{subject}",
289
+ msg.from_,
290
+ (
291
+ msg.date.strftime("%H:%M %d/%m/%Y")
292
+ if msg.date
293
+ else "???"
294
+ ),
295
+ )
230
296
  if len(table.rows) >= args.count:
231
297
  break
232
298
 
233
- console.print(table)
299
+ if args.json:
300
+ print_json(json.dumps(json_data))
301
+ else:
302
+ console.print(table)
234
303
  return 0
235
304
  except Exception:
236
305
  console.print_exception(show_locals=True)
@@ -1,7 +0,0 @@
1
- myl.py,sha256=igvvyQpWzIDu_-zrE9qfxp5kDBO5vpBYG5PE6dwUHek,7548
2
- myl-0.8.9.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
3
- myl-0.8.9.dist-info/METADATA,sha256=6kbZYilnkr5JfK_3EsGFDDZs2E_zwJtl50UvJaQT2bk,43280
4
- myl-0.8.9.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
5
- myl-0.8.9.dist-info/entry_points.txt,sha256=q6nr0Kzim7JzreXQE3BTU4asLh2sx5-D0w1yLBOcHxc,33
6
- myl-0.8.9.dist-info/top_level.txt,sha256=Wn88OJVVWyYSsKVoqzlHXxfFxh5IbrJ_Yw-ldNLe7Po,4
7
- myl-0.8.9.dist-info/RECORD,,
File without changes
File without changes