Skip to content

Commit a0b4845

Browse files
authored
Merge pull request #2 from DemocracyLab/sig
Sig
2 parents 174c965 + 5d22217 commit a0b4845

5 files changed

Lines changed: 29 additions & 11 deletions

File tree

‎Sample email for Generative AI.md‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Sample email for Generative AI
1+
# Sample email for Generative AI
22
Please write unique subject lines and emails using the sample below. Please follow the following rules:
33

44
- Rewrite the paragraphs, keeping the order and number of paragraphs from the sample
@@ -16,7 +16,7 @@ Please write unique subject lines and emails using the sample below. Please foll
1616
- For the two issues that are listed, don't put a space at the beginning of each line
1717
- Each of the two issues must be on a separate line.
1818
- Don't label the subject line and email body, just bold the subject line
19-
- Always end with, "Best,"
19+
- Always end with, "Best," the signature will come from the gmail sig
2020
- Every sentence other than links should be unique, don't repeat across emails unless otherwise instructed above
2121
- Write in a professional and friendly tone
2222
- The subject line must be text only, not Markdown or HTML
@@ -43,5 +43,3 @@ Thank you for considering this opportunity. We look forward to connecting with y
4343

4444
Best,
4545

46-
47-
David

‎package-lock.json‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ai-mail",
3-
"version": "1.0.8",
3+
"version": "1.0.9",
44
"description": "AI-powered email personalization tool with Gmail and Google Sheets integration",
55
"main": "dist-electron/index.js",
66
"type": "module",

‎src/main/gmail.ts‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ export function setupGmailHandlers(ipcMain: IpcMain, store: Store<AppConfig>, ma
103103
scope: [
104104
'https://www.googleapis.com/auth/gmail.send',
105105
'https://www.googleapis.com/auth/gmail.readonly',
106-
'https://www.googleapis.com/auth/spreadsheets'
106+
'https://www.googleapis.com/auth/spreadsheets',
107+
'https://www.googleapis.com/auth/gmail.settings.basic'
107108
],
108109
prompt: 'consent'
109110
});
@@ -208,14 +209,30 @@ export function setupGmailHandlers(ipcMain: IpcMain, store: Store<AppConfig>, ma
208209
refresh_token: config.google.refreshToken
209210
});
210211

212+
// Fetch user's signature
213+
let signature = '';
214+
try {
215+
const sendAsResponse = await gmail.users.settings.sendAs.list({
216+
auth: client,
217+
userId: 'me'
218+
});
219+
const aliases = sendAsResponse.data.sendAs || [];
220+
const alias = aliases.find(a => a.sendAsEmail === config.user.email) || aliases.find(a => a.isPrimary);
221+
if (alias && alias.signature) {
222+
signature = `<br><br>${alias.signature}`;
223+
}
224+
} catch (sigError) {
225+
console.warn('Failed to fetch signature:', sigError);
226+
}
227+
211228
// Create email
212229
const message = [
213230
`From: ${config.user.name} <${config.user.email}>`,
214231
`To: ${emailData.to}`,
215232
`Subject: ${emailData.subject}`,
216233
'Content-Type: text/html; charset=utf-8',
217234
'',
218-
emailData.body
235+
emailData.body + signature
219236
].join('\n');
220237

221238
const encodedMessage = Buffer.from(message)

‎src/renderer/App.tsx‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState, useEffect } from 'react';
1+
import { useState, useEffect, useRef } from 'react';
22
import { AppProvider, useApp } from './context/AppContext';
33
import ConfigTab from './components/ConfigTab';
44
import ContextTab from './components/ContextTab';
@@ -10,10 +10,11 @@ type Tab = 'config' | 'context' | 'email';
1010
function AppContent() {
1111
const { config } = useApp();
1212
const [activeTab, setActiveTab] = useState<Tab>('config');
13+
const initialTabSet = useRef(false);
1314

1415
// Determine initial tab based on configuration completeness
1516
useEffect(() => {
16-
if (!config) return;
17+
if (!config || initialTabSet.current) return;
1718

1819
// Check if configuration is complete
1920
const hasUserInfo = config.user.name && config.user.email;
@@ -33,6 +34,8 @@ function AppContent() {
3334
} else {
3435
setActiveTab('email');
3536
}
37+
38+
initialTabSet.current = true;
3639
}, [config]);
3740

3841
return (

0 commit comments

Comments
 (0)