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).

!7

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

  void start {
    ownTimer(doEvery(dm_osLoading() ? 10.0 : 0.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 = googleCode_gmail_inbox();
        temp tempMailStore(inbox);
        inbox.open(Folder.READ_ONLY);
        
        IMAPMessage msg = cast ((UIDFolder) inbox).getMessageByUID(uid);
        O content = msg.getContent();
        showText("Mail " + uid, javaMail_messageContentToText(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 = googleCode_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);
    Message[] messages = inbox.getMessages(n, count);
    
    print("Fetching " + n2(messages, "message"));
    inbox.fetch(messages, javaMail_fullFetchProfile());

    int i = 1;
    for (Message _msg : reversed(messages)) {
      new LinkedHashMap map;
      //print("Loading message " + i++);
      IMAPMessage msg = cast _msg;
      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");
    S oldLatest = latestMessageID();
    setField(data := l);
    if (nempty(oldLatest)) {
      S latest = latestMessageID();
      if (neq(oldLatest, latest)) 
        onClick(infoBoxPanel("New GMail from " + getString(first(l), "From") + "!"), rThread dm_toFront);
    }
    ret l;
  }
  
  S latestMessageID() {
    ret getString(first(data), "[hidden] ID");
  }
}

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: 483 / 55301
Version history: 16 change(s)
Referenced in: #1016634 - Sent GMails [Dyn Module]
#1019024 - Latest GMails v4 [Dyn Module] - apparently protocol has been disabled by Google?