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

87
LINES

< > BotCompany Repo | #1016632 // Latest GMails v3 [Dyn Module]

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

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

1  
!7
2  
3  
sclass LatestGMails extends DynTable {
4  
  int numMsgs = 50;
5  
  L<Map> data;
6  
7  
  void start {
8  
    ownTimer(doEvery(dm_osLoading() ? 10.0 : 0.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 = googleCode_gmail_inbox();
20  
        temp tempMailStore(inbox);
21  
        inbox.open(Folder.READ_ONLY);
22  
        
23  
        IMAPMessage msg = cast ((UIDFolder) inbox).getMessageByUID(uid);
24  
        O content = msg.getContent();
25  
        showText("Mail " + uid, javaMail_messageContentToText(content));
26  
      });
27  
    
28  
    ret c;
29  
  }
30  
  
31  
  L<Map> calc() {
32  
    temp enter();
33  
    if (data != null) ret data;
34  
    ret actualCalc();
35  
  }
36  
  
37  
  L<Map> actualCalc() ctex {
38  
    temp enter();
39  
    long startTime = sysNow();
40  
    Folder inbox = googleCode_gmail_inbox();
41  
    temp tempMailStore(inbox);
42  
    new L<Map> l;
43  
    inbox.open(Folder.READ_ONLY);
44  
    
45  
    int count = inbox.getMessageCount();
46  
    int n = max(1, count-numMsgs+1);
47  
    Message[] messages = inbox.getMessages(n, count);
48  
    
49  
    print("Fetching " + n2(messages, "message"));
50  
    inbox.fetch(messages, javaMail_fullFetchProfile());
51  
52  
    int i = 1;
53  
    for (Message _msg : reversed(messages)) {
54  
      new LinkedHashMap map;
55  
      //print("Loading message " + i++);
56  
      IMAPMessage msg = cast _msg;
57  
      map.put("From", InternetAddress.toString(msg.getFrom()));
58  
      map.put("Subject", msg.getSubject());
59  
      //map.put("Message number: " + msg.getMessageNumber());
60  
      map.put("Sent/Received", msg.getSentDate() + "/" + msg.getReceivedDate());
61  
      //O content = msg.getContent();
62  
      //print("  Content type: " + getClassName(content));
63  
      map.put("Size", toK(msg.getSize()) + " K");
64  
      map.put("[hidden] ID", msg.getMessageID());
65  
      pcall { map.put("UID", ((UIDFolder) inbox).getUID(msg)); }
66  
      //map.put("Content Type", className(content) + " / " + msg.getContentType());
67  
      map.put("Content Type", msg.getContentType());
68  
      //print("  Content type: " + msg.getContentType());
69  
      l.add(map);
70  
    }
71  
    //inbox.close(false);
72  
    //inbox.getStore().close();
73  
    print("Fetching " + n2(l, " latest GMail") + " took: " + elapsedTime(startTime) + " ms");
74  
    S oldLatest = latestMessageID();
75  
    setField(data := l);
76  
    if (nempty(oldLatest)) {
77  
      S latest = latestMessageID();
78  
      if (neq(oldLatest, latest)) 
79  
        onClick(infoBoxPanel("New GMail from " + getString(first(l), "From") + "!"), rThread dm_toFront);
80  
    }
81  
    ret l;
82  
  }
83  
  
84  
  S latestMessageID() {
85  
    ret getString(first(data), "[hidden] ID");
86  
  }
87  
}

Author comment

Began life as a copy of #1016630

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: #1016632
Snippet name: Latest GMails v3 [Dyn Module]
Eternal ID of this version: #1016632/17
Text MD5: b35bc3a230a73ef5ed72fbff5a62c30c
Transpilation MD5: 50a6cefa09789c690c885bba3c1fe9f9
Author: stefan
Category: javax
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-10-21 13:22:10
Source code size: 2860 bytes / 87 lines
Pitched / IR pitched: No / No
Views / Downloads: 484 / 55304
Version history: 16 change(s)
Referenced in: [show references]