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

!7

sclass LatestGMails extends DynObjectTable<Map> {
  int numMsgs = 50;

  start {
    ownTimer(doEvery(dm_osLoading() ? 10.0 : 0.0, 60.0, r calc));
    itemToMap = f_id();
  }
  
  visualize {
    JComponent c = super.visualize();
    tablePopupMenuItemsThreaded(table,
      "Show mail (source code)", r {
        temp WithAutoCloseable<O> content = selectedMailContent();
        S text = javaMail_messageContentToText(content!);
        if (text!= null) showText("Mail " + selectedMailUID(), text);
      },
      "Show mail (HTML)", r {
        temp WithAutoCloseable<O> content = selectedMailContent();
        print("Content class: " + className(content!));
        S text = javaMail_messageContentToText(content!);
        if (text != null) showFrame("Mail " + selectedMailUID(), jHTMLEditorPane(trim(text)));
      },
      "Reply...", r {
        S replyModule = dm_makeNewModule("#1016474/GMailSendForm");
        dm_setModule(replyModule, data := litorderedmap(
          "To:" := selectedTableCell(table, "From"),
          "Subject:" := addReToMailSubject((S) selectedTableCell(table, "Subject"))));
        dm_showModule(replyModule);
      });
    
    ret c;
  }

  long selectedMailUID() {
    ret parseLong((S) selectedTableCell(table, "UID"));
  }

  WithAutoCloseable<O> selectedMailContent() ctex {
    long uid = selectedMailUID();
    if (uid == 0) null;
    Folder inbox = googleCode_gmail_inbox();
    AutoCloseable temp = tempMailStore(inbox);
    inbox.open(Folder.READ_ONLY);
    
    IMAPMessage msg = cast ((UIDFolder) inbox).getMessageByUID(uid);
    //print("Message mime type: " + msg.getMimeType();
    ret WithAutoCloseable(temp, msg.getContent());
  }
  
  void calc() ctex {
    temp enter();
    if (dm_osShuttingDown()) ret;
    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();
    setData(l);
    if (nempty(oldLatest)) {
      S latest = latestMessageID();
      if (neq(oldLatest, latest)) 
        onClick(infoBoxPanel("New GMail from " + getString(first(l), "From") + "!"), rThread dm_toFront);
    }
  }
  
  S latestMessageID() {
    ret getString(first(data), "[hidden] ID");
  }
}

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: 296 / 7845
Version history: 18 change(s)
Referenced in: [show references]