myl 0.8.9__tar.gz → 0.8.10__tar.gz

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.10
4
4
  Summary: Dead simple IMAP CLI client
5
5
  Author-email: Philipp Schmitt <philipp@schmitt.co>
6
6
  License: GNU GENERAL PUBLIC LICENSE
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: myl
3
- Version: 0.8.9
3
+ Version: 0.8.10
4
4
  Summary: Dead simple IMAP CLI client
5
5
  Author-email: Philipp Schmitt <philipp@schmitt.co>
6
6
  License: GNU GENERAL PUBLIC LICENSE
@@ -1,11 +1,12 @@
1
1
  import argparse
2
+ import json
2
3
  import logging
3
4
  import ssl
4
5
  import sys
5
6
 
6
7
  import imap_tools
7
8
  from myldiscovery import autodiscover
8
- from rich import print
9
+ from rich import print, print_json
9
10
  from rich.console import Console
10
11
  from rich.logging import RichHandler
11
12
  from rich.table import Table
@@ -82,6 +83,13 @@ def parse_args():
82
83
  )
83
84
  parser.add_argument("-S", "--search", help="Search string", default="ALL")
84
85
  parser.add_argument("-H", "--html", help="Show HTML", action="store_true")
86
+ parser.add_argument(
87
+ "-j",
88
+ "--json",
89
+ help="JSON output",
90
+ action="store_true",
91
+ default=False,
92
+ )
85
93
  parser.add_argument(
86
94
  "-r",
87
95
  "--raw",
@@ -146,6 +154,7 @@ def main():
146
154
  )
147
155
  return 2
148
156
 
157
+ json_data = []
149
158
  table = Table(
150
159
  show_header=not args.no_title,
151
160
  header_style="bold",
@@ -200,6 +209,31 @@ def main():
200
209
  if args.raw:
201
210
  print(msg.obj.as_string())
202
211
  return 0
212
+ elif args.json:
213
+ print_json(
214
+ json.dumps(
215
+ {
216
+ "uid": msg.uid,
217
+ "subject": msg.subject,
218
+ "from": msg.from_,
219
+ "to": msg.to,
220
+ "date": msg.date.strftime(
221
+ "%Y-%m-%d %H:%M:%S"
222
+ ),
223
+ "timestamp": str(
224
+ int(msg.date.timestamp())
225
+ ),
226
+ "content": {
227
+ "raw": msg.obj.as_string(),
228
+ "html": msg.html,
229
+ "text": msg.text,
230
+ },
231
+ "attachments": msg.attachments,
232
+ }
233
+ )
234
+ )
235
+ return 0
236
+
203
237
  print(msg.text if not args.html else msg.html)
204
238
  for att in msg.attachments:
205
239
  print(
@@ -221,16 +255,41 @@ def main():
221
255
  if msg.subject
222
256
  else "<no-subject>"
223
257
  )
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
- )
258
+ if args.json:
259
+ json_data.append(
260
+ {
261
+ "uid": msg.uid,
262
+ "subject": msg.subject,
263
+ "from": msg.from_,
264
+ "to": msg.to,
265
+ "date": msg.date.strftime("%Y-%m-%d %H:%M:%S"),
266
+ "timestamp": str(int(msg.date.timestamp())),
267
+ "content": {
268
+ "raw": msg.obj.as_string(),
269
+ "html": msg.html,
270
+ "text": msg.text,
271
+ },
272
+ "attachments": msg.attachments,
273
+ }
274
+ )
275
+ else:
276
+ table.add_row(
277
+ msg.uid if msg.uid else "???",
278
+ f"{subj_prefix}{subject}",
279
+ msg.from_,
280
+ (
281
+ msg.date.strftime("%H:%M %d/%m/%Y")
282
+ if msg.date
283
+ else "???"
284
+ ),
285
+ )
230
286
  if len(table.rows) >= args.count:
231
287
  break
232
288
 
233
- console.print(table)
289
+ if args.json:
290
+ print_json(json.dumps(json_data))
291
+ else:
292
+ console.print(table)
234
293
  return 0
235
294
  except Exception:
236
295
  console.print_exception(show_locals=True)
@@ -20,7 +20,7 @@ dependencies = [
20
20
  "myl-discovery >= 0.6.0",
21
21
  "rich >= 13.0.0, <14.0.0",
22
22
  ]
23
- version = "0.8.9"
23
+ version = "0.8.10"
24
24
 
25
25
  [project.urls]
26
26
  homepage = "https://github.com/pschmitt/myl"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes