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

82
LINES

< > BotCompany Repo | #1016630 // Latest GMails v2 [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 (15245L/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 = googleCode_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 = googleCode_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  
}

Author comment

Began life as a copy of #1016066

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: #1016630
Snippet name: Latest GMails v2 [Dyn Module]
Eternal ID of this version: #1016630/4
Text MD5: 361f0c80d46002b0d796032ac40e3d53
Transpilation MD5: 884875adcfab5571237e1267aabc7fe3
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:01:34
Source code size: 2896 bytes / 82 lines
Pitched / IR pitched: No / No
Views / Downloads: 362 / 791
Version history: 3 change(s)
Referenced in: [show references]