Uses 715K of libraries. Click here for Pure Java version (15246L/108K).
1 | !7 |
2 | |
3 | sclass LatestGMails extends DynTable { |
4 | int numMsgs = 50; |
5 | L<Map> data; |
6 | |
7 | void start { |
8 | ownTimer(doEvery(10.0, 60.0, r actualUpdate)); |
9 | } |
10 | |
11 | void actualUpdate { actualCalc(); updateMe(); } |
12 | |
13 | JComponent visualize() { |
14 | JComponent c = super.visualize(); |
15 | tablePopupMenuItemsThreaded(table, |
16 | "Mail source code", r { |
17 | long uid = parseLong((S) selectedTableCell(table, "UID")); |
18 | if (uid == 0) ret; |
19 | Folder inbox = gmail_inbox(); |
20 | temp tempMailStore(inbox); |
21 | inbox.open(Folder.READ_ONLY); |
22 | IMAPMessage msg = cast ((UIDFolder) inbox).getMessageByUID(uid); |
23 | O content = msg.getContent(); |
24 | if (isString(content)) showText("Mail " + uid, content); |
25 | else if (content instanceof Multipart) { |
26 | Multipart mp = cast content; |
27 | int n = mp.getCount(); |
28 | new L<S> l; |
29 | for i to n: { |
30 | Part part = mp.getBodyPart(i); |
31 | S type = part.getContentType(); |
32 | O partContent = part.getContent(); |
33 | l.add(type + " / " + className(partContent)); |
34 | if (partContent instanceof S) |
35 | l.add(str(partContent)); |
36 | } |
37 | showText("Mail " + uid, joinWithEmptyLines(l)); |
38 | } else print("Unknown content type: " + className(content)); |
39 | }); |
40 | |
41 | ret c; |
42 | } |
43 | |
44 | L<Map> calc() { |
45 | temp enter(); |
46 | if (data != null) ret data; |
47 | ret actualCalc(); |
48 | } |
49 | |
50 | L<Map> actualCalc() ctex { |
51 | temp enter(); |
52 | long startTime = sysNow(); |
53 | Folder inbox = gmail_inbox(); |
54 | temp tempMailStore(inbox); |
55 | new L<Map> l; |
56 | inbox.open(Folder.READ_ONLY); |
57 | int count = inbox.getMessageCount(); |
58 | int n = max(1, count-numMsgs+1); |
59 | for (int i = count; i >= n; i--) { |
60 | new LinkedHashMap map; |
61 | //print("\nLoading message " + i + "\n"); |
62 | IMAPMessage msg = cast inbox.getMessage(i); |
63 | map.put("From", InternetAddress.toString(msg.getFrom())); |
64 | map.put("Subject", msg.getSubject()); |
65 | //map.put("Message number: " + msg.getMessageNumber()); |
66 | map.put("Sent/Received", msg.getSentDate() + "/" + msg.getReceivedDate()); |
67 | //O content = msg.getContent(); |
68 | //print(" Content type: " + getClassName(content)); |
69 | map.put("Size", toK(msg.getSize()) + " K"); |
70 | map.put("[hidden] ID", msg.getMessageID()); |
71 | pcall { map.put("UID", ((UIDFolder) inbox).getUID(msg)); } |
72 | //map.put("Content Type", className(content) + " / " + msg.getContentType()); |
73 | map.put("Content Type", msg.getContentType()); |
74 | //print(" Content type: " + msg.getContentType()); |
75 | l.add(map); |
76 | } |
77 | //inbox.close(false); |
78 | //inbox.getStore().close(); |
79 | print("Fetching " + n2(l, " latest GMail") + " took: " + elapsedTime(startTime) + " ms"); |
80 | ret setFieldAndReturn(data := l); |
81 | } |
82 | } |
Began life as a copy of #1015978
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1016066 |
Snippet name: | Latest GMails [Dyn Module] |
Eternal ID of this version: | #1016066/38 |
Text MD5: | 4b3cc022207c10a78159134e4f60aa9f |
Transpilation MD5: | a5935081e51569b02a9e0cd60e8e1f19 |
Author: | stefan |
Category: | javax |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-06-25 23:00:35 |
Source code size: | 2876 bytes / 82 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 626 / 13966 |
Version history: | 37 change(s) |
Referenced in: | [show references] |