Logic Machine Forum
Outlook calendar - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Outlook calendar (/showthread.php?tid=4135)



Outlook calendar - a455115 - 07.07.2022

Hello,

I searched but didn't find anything in the search engine, so I'm opening a new topic.

I need a script for outlook that can take information from the calendar. The idea is to be able to turn on the ventilation in a hall automatically during the hours in which the hall is engaged via email. It would be nice if information about who saved it and the topic of the meeting could be retrieved. Is it possible to do something like this?


RE: Outlook calendar - emme - 07.07.2022

this could be a good starting point....
https://stackoverflow.com/questions/24260008/how-to-read-e-mails-with-lua

we do only need imap4 and pop3 library availble in LM Wink


RE: Outlook calendar - admin - 07.07.2022

It can be added to LM as a user library: https://github.com/jesrui/imap4.lua/blob/add-idle-command/imap4.lua (slightly updated version with some fixes)


RE: Outlook calendar - a455115 - 11.07.2022

(07.07.2022, 08:45)admin Wrote: It can be added to LM as a user library: https://github.com/jesrui/imap4.lua/blob/add-idle-command/imap4.lua (slightly updated version with some fixes)

Hello,

Unfortunately, I'm a newbie to programming and I'm having a hard time understanding the code. Can you refer me to some additional literature on imap4.lua


RE: Outlook calendar - admin - 12.07.2022

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



RE: Outlook calendar - a455115 - 12.07.2022

(12.07.2022, 11:01)admin Wrote: 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()
What I want to do is analyze an ICS file. When someone sends a meeting invitation with an ICS file to a LM email, the script should store in an object the names of the sender, the subject of the email, if the time slot is free to confirm the meeting and run a certain scene say 30 minutes before the meeting. Also if there is already an engagement in that time slot to send the appointment rejection. I don't know where and how to schedule the occupancy of the hall.


RE: Outlook calendar - admin - 12.07.2022

While this is doable this is too complicated and won't be a 100% stable solution.
There's an option to access Outlook calendar via API: https://docs.microsoft.com/en-us/graph/api/resources/calendar?view=graph-rest-1.0&preserve-view=true
Example of a similar integration: https://forum.logicmachine.net/showthread.php?tid=3059


RE: Outlook calendar - a455115 - 13.07.2022

(12.07.2022, 13:54)admin Wrote: While this is doable this is too complicated and won't be a 100% stable solution.
There's an option to access Outlook calendar via API: https://docs.microsoft.com/en-us/graph/api/resources/calendar?view=graph-rest-1.0&preserve-view=true
Example of a similar integration: https://forum.logicmachine.net/showthread.php?tid=3059

Thanks for the help, I'll look into it and try it out