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

95
LINES

< > BotCompany Repo | #1016634 // Sent GMails [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 (15280L/108K).

1  
!7
2  
3  
sclass SentGMails 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 = theFolder();
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  
        if (isString(content)) showText("Mail " + uid, content);
26  
        else if (content instanceof Multipart) {
27  
          Multipart mp = cast content;
28  
          int n = mp.getCount();
29  
          new L<S> l;
30  
          for i to n: {
31  
            Part part = mp.getBodyPart(i);
32  
            S type = part.getContentType();
33  
            O partContent = part.getContent();
34  
            l.add(type + " / " + className(partContent));
35  
            if (partContent instanceof S)
36  
              l.add(str(partContent));
37  
          }
38  
          showText("Mail " + uid, joinWithEmptyLines(l));
39  
        } else print("Unknown content type: " + className(content));
40  
      });
41  
    
42  
    ret c;
43  
  }
44  
  
45  
  L<Map> calc() {
46  
    temp enter();
47  
    if (data != null) ret data;
48  
    pcall { ret actualCalc(); }
49  
    null;
50  
  }
51  
  
52  
  L<Map> actualCalc() ctex {
53  
    temp enter();
54  
    long startTime = sysNow();
55  
    Folder inbox = theFolder();
56  
    temp tempMailStore(inbox);
57  
    new L<Map> l;
58  
    inbox.open(Folder.READ_ONLY);
59  
    
60  
    int count = inbox.getMessageCount();
61  
    int n = max(1, count-numMsgs+1);
62  
    Message[] messages = inbox.getMessages(n, count);
63  
    
64  
    print("Fetching " + n2(messages, "message"));
65  
    inbox.fetch(messages, javaMail_fullFetchProfile());
66  
67  
    int i = 1;
68  
    for (Message _msg : reversed(messages)) {
69  
      new LinkedHashMap map;
70  
      //print("Loading message " + i++);
71  
      IMAPMessage msg = cast _msg;
72  
      map.put("To", InternetAddress.toString(msg.getRecipients(Message.RecipientType.TO)));
73  
      map.put("Subject", msg.getSubject());
74  
      //map.put("Message number: " + msg.getMessageNumber());
75  
      map.put("Sent/Received", msg.getSentDate() + "/" + msg.getReceivedDate());
76  
      //O content = msg.getContent();
77  
      //print("  Content type: " + getClassName(content));
78  
      map.put("Size", toK(msg.getSize()) + " K");
79  
      map.put("[hidden] ID", msg.getMessageID());
80  
      pcall { map.put("UID", ((UIDFolder) inbox).getUID(msg)); }
81  
      //map.put("Content Type", className(content) + " / " + msg.getContentType());
82  
      map.put("Content Type", msg.getContentType());
83  
      //print("  Content type: " + msg.getContentType());
84  
      l.add(map);
85  
    }
86  
    //inbox.close(false);
87  
    //inbox.getStore().close();
88  
    print("Fetching " + n2(l, " latest GMail") + " took: " + elapsedTime(startTime) + " ms");
89  
    ret setFieldAndReturn(data := l);
90  
  }
91  
  
92  
  Folder theFolder() {
93  
    ret googleCode_gmail_folder("[Google Mail]/Sent Mail");
94  
  }
95  
}

Author comment

Began life as a copy of #1016632

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: #1016634
Snippet name: Sent GMails [Dyn Module]
Eternal ID of this version: #1016634/9
Text MD5: ee7d138a70741332bb6257fa0bc611b9
Transpilation MD5: e1e549e3b60efef2e80fa280c4cedc2e
Author: stefan
Category: javax
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-07-06 14:45:41
Source code size: 3201 bytes / 95 lines
Pitched / IR pitched: No / No
Views / Downloads: 446 / 978
Version history: 8 change(s)
Referenced in: [show references]