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

82
LINES

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

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

Uses 715K of libraries. Click here for Pure Java version (15246L/108K).

!7

sclass LatestGMails extends DynTable {
  int numMsgs = 50;
  L<Map> data;

  void start {
    ownTimer(doEvery(10.0, 60.0, r actualUpdate));
  }
  
  void actualUpdate { actualCalc(); updateMe(); }
  
  JComponent visualize() {
    JComponent c = super.visualize();
    tablePopupMenuItemsThreaded(table,
      "Mail source code", r {
        long uid = parseLong((S) selectedTableCell(table, "UID"));
        if (uid == 0) ret;
        Folder inbox = gmail_inbox();
        temp tempMailStore(inbox);
        inbox.open(Folder.READ_ONLY);
        IMAPMessage msg = cast ((UIDFolder) inbox).getMessageByUID(uid);
        O content = msg.getContent();
        if (isString(content)) showText("Mail " + uid, content);
        else if (content instanceof Multipart) {
          Multipart mp = cast content;
          int n = mp.getCount();
          new L<S> l;
          for i to n: {
            Part part = mp.getBodyPart(i);
            S type = part.getContentType();
            O partContent = part.getContent();
            l.add(type + " / " + className(partContent));
            if (partContent instanceof S)
              l.add(str(partContent));
          }
          showText("Mail " + uid, joinWithEmptyLines(l));
        } else print("Unknown content type: " + className(content));
      });
    
    ret c;
  }
  
  L<Map> calc() {
    temp enter();
    if (data != null) ret data;
    ret actualCalc();
  }
  
  L<Map> actualCalc() ctex {
    temp enter();
    long startTime = sysNow();
    Folder inbox = gmail_inbox();
    temp tempMailStore(inbox);
    new L<Map> l;
    inbox.open(Folder.READ_ONLY);
    int count = inbox.getMessageCount();
    int n = max(1, count-numMsgs+1);
    for (int i = count; i >= n; i--) {
      new LinkedHashMap map;
      //print("\nLoading message " + i + "\n");
      IMAPMessage msg = cast inbox.getMessage(i);
      map.put("From", InternetAddress.toString(msg.getFrom()));
      map.put("Subject", msg.getSubject());
      //map.put("Message number: " + msg.getMessageNumber());
      map.put("Sent/Received", msg.getSentDate() + "/" + msg.getReceivedDate());
      //O content = msg.getContent();
      //print("  Content type: " + getClassName(content));
      map.put("Size", toK(msg.getSize()) + " K");
      map.put("[hidden] ID", msg.getMessageID());
      pcall { map.put("UID", ((UIDFolder) inbox).getUID(msg)); }
      //map.put("Content Type", className(content) + " / " + msg.getContentType());
      map.put("Content Type", msg.getContentType());
      //print("  Content type: " + msg.getContentType());
      l.add(map);
    }
    //inbox.close(false);
    //inbox.getStore().close();
    print("Fetching " + n2(l, " latest GMail") + " took: " + elapsedTime(startTime) + " ms");
    ret setFieldAndReturn(data := l);
  }
}

Author comment

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: 622 / 13962
Version history: 37 change(s)
Referenced in: #1016630 - Latest GMails v2 [Dyn Module]