Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

102
LINES

< > BotCompany Repo | #1019024 // Latest GMails v4 [Dyn Module] - apparently protocol has been disabled by Google?

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 557K of libraries. Click here for Pure Java version (33094L/209K).

1  
!7
2  
3  
sclass LatestGMails extends DynObjectTable<Map> {
4  
  int numMsgs = 50;
5  
6  
  start {
7  
    ownTimer(doEvery(dm_osLoading() ? 10.0 : 0.0, 60.0, r calc));
8  
    itemToMap = f_id();
9  
  }
10  
  
11  
  visualize {
12  
    JComponent c = super.visualize();
13  
    tablePopupMenuItemsThreaded(table,
14  
      "Show mail (source code)", r {
15  
        temp WithAutoCloseable<O> content = selectedMailContent();
16  
        S text = javaMail_messageContentToText(content!);
17  
        if (text!= null) showText("Mail " + selectedMailUID(), text);
18  
      },
19  
      "Show mail (HTML)", r {
20  
        temp WithAutoCloseable<O> content = selectedMailContent();
21  
        print("Content class: " + className(content!));
22  
        S text = javaMail_messageContentToText(content!);
23  
        if (text != null) showFrame("Mail " + selectedMailUID(), jHTMLEditorPane(trim(text)));
24  
      },
25  
      "Reply...", r {
26  
        S replyModule = dm_makeNewModule("#1016474/GMailSendForm");
27  
        dm_setModule(replyModule, data := litorderedmap(
28  
          "To:" := selectedTableCell(table, "From"),
29  
          "Subject:" := addReToMailSubject((S) selectedTableCell(table, "Subject"))));
30  
        dm_showModule(replyModule);
31  
      });
32  
    
33  
    ret c;
34  
  }
35  
36  
  long selectedMailUID() {
37  
    ret parseLong((S) selectedTableCell(table, "UID"));
38  
  }
39  
40  
  WithAutoCloseable<O> selectedMailContent() ctex {
41  
    long uid = selectedMailUID();
42  
    if (uid == 0) null;
43  
    Folder inbox = googleCode_gmail_inbox();
44  
    AutoCloseable temp = tempMailStore(inbox);
45  
    inbox.open(Folder.READ_ONLY);
46  
    
47  
    IMAPMessage msg = cast ((UIDFolder) inbox).getMessageByUID(uid);
48  
    //print("Message mime type: " + msg.getMimeType();
49  
    ret WithAutoCloseable(temp, msg.getContent());
50  
  }
51  
  
52  
  void calc() ctex {
53  
    temp enter();
54  
    if (dm_osShuttingDown()) ret;
55  
    long startTime = sysNow();
56  
    Folder inbox = googleCode_gmail_inbox();
57  
    temp tempMailStore(inbox);
58  
    new L<Map> l;
59  
    inbox.open(Folder.READ_ONLY);
60  
    
61  
    int count = inbox.getMessageCount();
62  
    int n = max(1, count-numMsgs+1);
63  
    Message[] messages = inbox.getMessages(n, count);
64  
    
65  
    print("Fetching " + n2(messages, "message"));
66  
    inbox.fetch(messages, javaMail_fullFetchProfile());
67  
68  
    int i = 1;
69  
    for (Message _msg : reversed(messages)) {
70  
      new LinkedHashMap map;
71  
      //print("Loading message " + i++);
72  
      IMAPMessage msg = cast _msg;
73  
      map.put("From", InternetAddress.toString(msg.getFrom()));
74  
      map.put("Subject", msg.getSubject());
75  
      //map.put("Message number: " + msg.getMessageNumber());
76  
      map.put("Sent/Received", msg.getSentDate() + "/" + msg.getReceivedDate());
77  
      //O content = msg.getContent();
78  
      //print("  Content type: " + getClassName(content));
79  
      map.put("Size", toK(msg.getSize()) + " K");
80  
      map.put("[hidden] ID", msg.getMessageID());
81  
      pcall { map.put("UID", ((UIDFolder) inbox).getUID(msg)); }
82  
      //map.put("Content Type", className(content) + " / " + msg.getContentType());
83  
      map.put("Content Type", msg.getContentType());
84  
      //print("  Content type: " + msg.getContentType());
85  
      l.add(map);
86  
    }
87  
    //inbox.close(false);
88  
    //inbox.getStore().close();
89  
    print("Fetching " + n2(l, " latest GMail") + " took: " + elapsedTime(startTime) + " ms");
90  
    S oldLatest = latestMessageID();
91  
    setData(l);
92  
    if (nempty(oldLatest)) {
93  
      S latest = latestMessageID();
94  
      if (neq(oldLatest, latest)) 
95  
        onClick(infoBoxPanel("New GMail from " + getString(first(l), "From") + "!"), rThread dm_toFront);
96  
    }
97  
  }
98  
  
99  
  S latestMessageID() {
100  
    ret getString(first(data), "[hidden] ID");
101  
  }
102  
}

Author comment

Began life as a copy of #1016632

download  show line numbers  debug dex  old transpilations   

Travelled to 12 computer(s): bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1019024
Snippet name: Latest GMails v4 [Dyn Module] - apparently protocol has been disabled by Google?
Eternal ID of this version: #1019024/19
Text MD5: 6d0d1a40110b8ff884a91a5a8eeb8f80
Transpilation MD5: 953e528f99a32eadac8d946a77a81bc7
Author: stefan
Category: javax
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2023-03-01 19:26:44
Source code size: 3674 bytes / 102 lines
Pitched / IR pitched: No / No
Views / Downloads: 375 / 7963
Version history: 18 change(s)
Referenced in: [show references]