Corrected Imapsync
Added different Tags feature to imapsync
This commit is contained in:
@@ -24,10 +24,9 @@ function openInbox(imapClient, cb) {
|
|||||||
imapClient.openBox('INBOX', false, cb);
|
imapClient.openBox('INBOX', false, cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
const uploadAttachmentToSupabase = async (tenant, folder ,file ) => {
|
const uploadAttachmentToSupabase = async (tenant, tags ,file ) => {
|
||||||
console.log("Start Upload")
|
console.log("Start Upload")
|
||||||
console.log(tenant)
|
console.log(tenant)
|
||||||
console.log(folder)
|
|
||||||
console.log(file)
|
console.log(file)
|
||||||
|
|
||||||
//Create Blob from File Content with Mime Type
|
//Create Blob from File Content with Mime Type
|
||||||
@@ -37,8 +36,8 @@ const uploadAttachmentToSupabase = async (tenant, folder ,file ) => {
|
|||||||
|
|
||||||
|
|
||||||
const {data: storageData,error: storageError} = await supabase.storage
|
const {data: storageData,error: storageError} = await supabase.storage
|
||||||
.from("documents")
|
.from("files")
|
||||||
.upload(`${tenant}/${folder}/${file.filename}`,blob)
|
.upload(`${tenant}/${file.filename}`,blob)
|
||||||
|
|
||||||
console.log(storageData)
|
console.log(storageData)
|
||||||
console.log(storageError)
|
console.log(storageError)
|
||||||
@@ -47,9 +46,7 @@ const uploadAttachmentToSupabase = async (tenant, folder ,file ) => {
|
|||||||
const {data: tableData,error: tableError} = await supabase
|
const {data: tableData,error: tableError} = await supabase
|
||||||
.from("documents")
|
.from("documents")
|
||||||
.insert({
|
.insert({
|
||||||
object: storageData.id,
|
tags: ["E-Mail Anhang", ...tags],
|
||||||
folder: folder,
|
|
||||||
tags: ["E-Mail Anhang"],
|
|
||||||
path: storageData.path,
|
path: storageData.path,
|
||||||
tenant: tenant
|
tenant: tenant
|
||||||
|
|
||||||
@@ -131,21 +128,28 @@ function processEmails () {
|
|||||||
let attach = null
|
let attach = null
|
||||||
//console.log((await simpleParser(buffer))) -> to see entire data of email
|
//console.log((await simpleParser(buffer))) -> to see entire data of email
|
||||||
let attachments = (await simpleParser(buffer)).attachments
|
let attachments = (await simpleParser(buffer)).attachments
|
||||||
/* if(((await simpleParser(buffer)).attachments).length != 0) {
|
|
||||||
|
|
||||||
|
let selectedInbox = "Eingang"
|
||||||
|
let toInboxes = (await simpleParser(buffer)).to.value
|
||||||
|
toInboxes.forEach(inbox => {
|
||||||
|
let temp = inbox.address.split("@")[0]
|
||||||
|
|
||||||
attach = (await simpleParser(buffer)).attachments[0].content //to get attachments
|
if(temp === "info") {
|
||||||
let file = (await simpleParser(buffer)).attachments[0]
|
selectedInbox = "Eingang"
|
||||||
console.log(file)
|
} else if (temp === "rechnung") {
|
||||||
fs.writeFile(file.filename,file.content, "binary", (err) => {
|
selectedInbox = "Eingangsrechnung"
|
||||||
if(!err) console.log("Success")
|
}
|
||||||
})
|
})
|
||||||
}*/
|
|
||||||
|
|
||||||
|
console.log(selectedInbox)
|
||||||
|
|
||||||
|
attachments.forEach(attachment => uploadAttachmentToSupabase(tenant.id, [selectedInbox], attachment))
|
||||||
|
|
||||||
|
|
||||||
if (info.which !== 'TEXT'){
|
if (info.which !== 'TEXT'){
|
||||||
let dataheader = Imap.parseHeader(buffer)
|
let dataheader = Imap.parseHeader(buffer)
|
||||||
|
|
||||||
//start -> set data, that you want to save on your DB
|
|
||||||
let emails_data = {
|
let emails_data = {
|
||||||
"date": dataheader.date[0],
|
"date": dataheader.date[0],
|
||||||
"subject": dataheader.subject[0],
|
"subject": dataheader.subject[0],
|
||||||
@@ -154,14 +158,7 @@ function processEmails () {
|
|||||||
"content": (await simpleParser(buffer)).text,
|
"content": (await simpleParser(buffer)).text,
|
||||||
"attachments": attachments
|
"attachments": attachments
|
||||||
}
|
}
|
||||||
//console.log(emails_data)
|
|
||||||
//end -> set data
|
|
||||||
|
|
||||||
attachments.forEach(attachment => uploadAttachmentToSupabase(tenant.id, "Eingang", attachment))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//tenantEmailArray.push(emails_data)
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
console.log(prefix + 'Body [%s] Finished', inspect(info.which));
|
console.log(prefix + 'Body [%s] Finished', inspect(info.which));
|
||||||
@@ -233,6 +230,8 @@ function processEmails () {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
processEmails()
|
||||||
|
|
||||||
setInterval(processEmails,interval * 1000)
|
setInterval(processEmails,interval * 1000)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user