Skip to content

Commit

Permalink
fix build failed bug
Browse files Browse the repository at this point in the history
  • Loading branch information
thingnotok committed Mar 3, 2023
1 parent 6b82186 commit d72e84e
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 20 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-google-mail",
"name": "Google Mail",
"version": "1.3.0",
"version": "1.4.1",
"minAppVersion": "0.15.0",
"description": "It fetches Google Mail as md notes. For note taking on newletters and idea collections.",
"author": "Lite C",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-google-mail",
"version": "1.3.0",
"version": "1.4.1",
"description": "It fetches Google Mail as md notes. For note taking on newletters and idea collections.",
"main": "main.js",
"keywords": [],
Expand Down
31 changes: 19 additions & 12 deletions src/GmailAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,22 +120,16 @@ function cleanFilename(filename: string) {
return filename.replace(/[\\/:"*?<>|]+/g, '_')
}

async function getAttachment(gmail, account: string, message_id: string, attachment_id: string) {
async function getAttachment(gmail:gmail_v1.Gmail, account: string, message_id: string, attachment_id: string) {
const res = await gmail.users.messages.attachments.get({
userId: account,
messageId: message_id,
id: attachment_id
});
return res
}
function hasAttachment(payload){
if(!payload.parts[0].parts)
return false;
else
return true;
}

const b64toBlob = (b64Data, contentType='', sliceSize=512) => {
const b64toBlob = (b64Data:string, contentType='', sliceSize=512) => {
const byteCharacters = atob(b64Data);
const byteArrays = [];

Expand All @@ -155,14 +149,14 @@ const b64toBlob = (b64Data, contentType='', sliceSize=512) => {
return blob;
}

async function getAttachments(gmail, account, msgId: string, parts, folder){
async function getAttachments(gmail:gmail_v1.Gmail, account:string, msgId: string, parts:any, folder:string){
const files = Array<string>();
for(let i = 0; i < parts.length; i++){
const part = parts[i];
const filename = part.filename
const attach_id = part.body.attachmentId
const ares = await getAttachment(gmail, account, msgId, attach_id)
const red = ares.data.data.replace(/-/g, '+').replace(/_/g, '/')
const red = ares.data?.data?.replace(/-/g, '+').replace(/_/g, '/') || ""
const init_name = filename
const final_name = await incr_filename(init_name, folder)
await this.app.vault.createBinary(final_name, base64ToArrayBuffer(red))
Expand All @@ -171,7 +165,7 @@ async function getAttachments(gmail, account, msgId: string, parts, folder){
return files
}

function flatten_parts(dst, parts){
function flatten_parts(dst:any, parts:any){
if(parts.length == 2 && parts[0].mimeType =='text/plain' && parts[1].mimeType =='text/html'){
dst.mtxt = parts[0].body
dst.mhtml = parts[1].body
Expand All @@ -190,6 +184,12 @@ function flatten_parts(dst, parts){
}
}

interface mail_obj{
assets: Array<any>,
mhtml: string,
mtxt: string
}

async function saveMail(settings: ObsGMailSettings, id: string) {
const note = await obtainTemplate(settings.template)
const noteName_template = settings.noteName
Expand All @@ -210,8 +210,15 @@ async function saveMail(settings: ObsGMailSettings, id: string) {
let title = formatTitle(fields.get('${Subject}') || "")
// Fetch the last mail in the threads
const payload = res.data.messages.pop().payload
const dst = {assets: Array<any>()}
const dst:mail_obj = {assets: Array<any>(), mhtml:"", mtxt:""}
flatten_parts(dst, payload.parts)
if(dst.mhtml=="" && dst.mtxt==""){
dst.mhtml = dst.assets.pop().body.data;
dst.mtxt = dst.mhtml;
}
console.log("DST:")
console.log(payload)
console.log(dst)
const body = await processBody([dst.mtxt, dst.mhtml], note.body_format)
fields.set('${Body}', body)
fields.set('${Link}', `https://mail.google.com/mail/#all/${id}`)
Expand Down
8 changes: 5 additions & 3 deletions src/mailProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ async function getMailTitle(title_candidates) {
return title
}

async function getBody(bodys, format){
async function getBody(bodys:any, format:any){
let body = ''
if (format == "htmlmd")
body = await processHTMLBody(bodys[1].data || "")
else if (format == "text")
body = await processPTBody(bodys[0].data || "")
else
body = await processRawBody(bodys[1].data || "")
if (body=="")
body = await processRawBody(bodys[1].data || bodys[0].data || "")
return body
}

Expand Down Expand Up @@ -137,8 +139,8 @@ function findTitle(list: Array<any>): string {

export async function incr_filename(title: string, folder: string) {
const name_sp = title.split('.')
const ext = name_sp[1]
const ori_name = name_sp[0]
const ext = name_sp.pop()
const ori_name = name_sp.join('.')
let tmp = ori_name
let isExist = await this.app.vault.exists(`${folder}/${tmp}.${ext}`)
let idx = 1
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"1.0.0": "0.15.0",
"2.0.0": "0.15.0",
"1.2.0": "0.15.0",
"1.3.0": "0.15.0"
"1.3.0": "0.15.0",
"1.4.1": "0.15.0"
}

0 comments on commit d72e84e

Please sign in to comment.