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);
|
||||
}
|
||||
|
||||
const uploadAttachmentToSupabase = async (tenant, folder ,file ) => {
|
||||
const uploadAttachmentToSupabase = async (tenant, tags ,file ) => {
|
||||
console.log("Start Upload")
|
||||
console.log(tenant)
|
||||
console.log(folder)
|
||||
console.log(file)
|
||||
|
||||
//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
|
||||
.from("documents")
|
||||
.upload(`${tenant}/${folder}/${file.filename}`,blob)
|
||||
.from("files")
|
||||
.upload(`${tenant}/${file.filename}`,blob)
|
||||
|
||||
console.log(storageData)
|
||||
console.log(storageError)
|
||||
@@ -47,9 +46,7 @@ const uploadAttachmentToSupabase = async (tenant, folder ,file ) => {
|
||||
const {data: tableData,error: tableError} = await supabase
|
||||
.from("documents")
|
||||
.insert({
|
||||
object: storageData.id,
|
||||
folder: folder,
|
||||
tags: ["E-Mail Anhang"],
|
||||
tags: ["E-Mail Anhang", ...tags],
|
||||
path: storageData.path,
|
||||
tenant: tenant
|
||||
|
||||
@@ -131,21 +128,28 @@ function processEmails () {
|
||||
let attach = null
|
||||
//console.log((await simpleParser(buffer))) -> to see entire data of email
|
||||
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]
|
||||
|
||||
if(temp === "info") {
|
||||
selectedInbox = "Eingang"
|
||||
} else if (temp === "rechnung") {
|
||||
selectedInbox = "Eingangsrechnung"
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
attach = (await simpleParser(buffer)).attachments[0].content //to get attachments
|
||||
let file = (await simpleParser(buffer)).attachments[0]
|
||||
console.log(file)
|
||||
fs.writeFile(file.filename,file.content, "binary", (err) => {
|
||||
if(!err) console.log("Success")
|
||||
})
|
||||
}*/
|
||||
console.log(selectedInbox)
|
||||
|
||||
attachments.forEach(attachment => uploadAttachmentToSupabase(tenant.id, [selectedInbox], attachment))
|
||||
|
||||
|
||||
if (info.which !== 'TEXT'){
|
||||
let dataheader = Imap.parseHeader(buffer)
|
||||
|
||||
//start -> set data, that you want to save on your DB
|
||||
let emails_data = {
|
||||
"date": dataheader.date[0],
|
||||
"subject": dataheader.subject[0],
|
||||
@@ -154,14 +158,7 @@ function processEmails () {
|
||||
"content": (await simpleParser(buffer)).text,
|
||||
"attachments": attachments
|
||||
}
|
||||
//console.log(emails_data)
|
||||
//end -> set data
|
||||
|
||||
attachments.forEach(attachment => uploadAttachmentToSupabase(tenant.id, "Eingang", attachment))
|
||||
|
||||
|
||||
|
||||
//tenantEmailArray.push(emails_data)
|
||||
}
|
||||
else
|
||||
console.log(prefix + 'Body [%s] Finished', inspect(info.which));
|
||||
@@ -233,6 +230,8 @@ function processEmails () {
|
||||
})
|
||||
}
|
||||
|
||||
processEmails()
|
||||
|
||||
setInterval(processEmails,interval * 1000)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user