This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Outlook calendar
#5
Use attached imap.lua to create a user library called imap.
This example fetches 3 newest emails from inbox. (App password is needed for this to work with Gmail dues to 2-step auth requirements).
For each email the first 8k (8192 bytes) of data is fetched. Fetching the whole email can lead to an out-of-memory condition if it has a large attachment. Each email has a unique id (UID) which should be an always increasing value. You can put the maximum UID of already parsed message into storage to skip emails that have already been parsed. Extracting data from the email depends on the format. Usually it's HTML split into lines with fixed width so parsing it might be tricky, unless there's an ICS file attached.

Code:
user = 'user@gmail.com'
pass = 'PASSWORD'

imap = require('user.imap')
conn = imap('imap.gmail.com', 993, { protocol = 'tlsv1_2' })

caps = conn:login(user, pass)
info = conn:examine('INBOX')

mcnt = 3 -- number of messages to fetch
query = math.max(1, info.exist - mcnt)
msgs = conn:fetch('(UID BODY.PEEK[HEADER.FIELDS (From Date Subject)])', query .. ':*')

for _, msg in pairs(msgs) do
  log('message', msg.id, msg.UID, msg.BODY.value)

  data = conn:fetch('BODY[]<0.8192>', msg.id)
  log(data[1].BODY.value)
end

conn:logout()

Attached Files
.lua   imap.lua (Size: 17.76 KB / Downloads: 12)
Reply


Messages In This Thread
Outlook calendar - by a455115 - 07.07.2022, 06:31
RE: Outlook calendar - by emme - 07.07.2022, 08:40
RE: Outlook calendar - by admin - 07.07.2022, 08:45
RE: Outlook calendar - by a455115 - 11.07.2022, 12:19
RE: Outlook calendar - by admin - 12.07.2022, 11:01
RE: Outlook calendar - by a455115 - 12.07.2022, 13:42
RE: Outlook calendar - by admin - 12.07.2022, 13:54
RE: Outlook calendar - by a455115 - 13.07.2022, 11:15

Forum Jump: