fetch2gmail 1.1.6__tar.gz → 1.1.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {fetch2gmail-1.1.6/src/fetch2gmail.egg-info → fetch2gmail-1.1.7}/PKG-INFO +1 -1
- {fetch2gmail-1.1.6 → fetch2gmail-1.1.7}/pyproject.toml +1 -1
- {fetch2gmail-1.1.6 → fetch2gmail-1.1.7/src/fetch2gmail.egg-info}/PKG-INFO +1 -1
- {fetch2gmail-1.1.6 → fetch2gmail-1.1.7}/src/fetcher/auth_server.py +3 -2
- {fetch2gmail-1.1.6 → fetch2gmail-1.1.7}/src/fetcher/cli.py +18 -3
- {fetch2gmail-1.1.6 → fetch2gmail-1.1.7}/src/fetcher/web_ui.py +111 -56
- {fetch2gmail-1.1.6 → fetch2gmail-1.1.7}/LICENSE +0 -0
- {fetch2gmail-1.1.6 → fetch2gmail-1.1.7}/README.md +0 -0
- {fetch2gmail-1.1.6 → fetch2gmail-1.1.7}/setup.cfg +0 -0
- {fetch2gmail-1.1.6 → fetch2gmail-1.1.7}/src/fetch2gmail.egg-info/SOURCES.txt +0 -0
- {fetch2gmail-1.1.6 → fetch2gmail-1.1.7}/src/fetch2gmail.egg-info/dependency_links.txt +0 -0
- {fetch2gmail-1.1.6 → fetch2gmail-1.1.7}/src/fetch2gmail.egg-info/entry_points.txt +0 -0
- {fetch2gmail-1.1.6 → fetch2gmail-1.1.7}/src/fetch2gmail.egg-info/requires.txt +0 -0
- {fetch2gmail-1.1.6 → fetch2gmail-1.1.7}/src/fetch2gmail.egg-info/top_level.txt +0 -0
- {fetch2gmail-1.1.6 → fetch2gmail-1.1.7}/src/fetcher/__init__.py +0 -0
- {fetch2gmail-1.1.6 → fetch2gmail-1.1.7}/src/fetcher/auth_ui.py +0 -0
- {fetch2gmail-1.1.6 → fetch2gmail-1.1.7}/src/fetcher/config.py +0 -0
- {fetch2gmail-1.1.6 → fetch2gmail-1.1.7}/src/fetcher/env_file.py +0 -0
- {fetch2gmail-1.1.6 → fetch2gmail-1.1.7}/src/fetcher/gmail_client.py +0 -0
- {fetch2gmail-1.1.6 → fetch2gmail-1.1.7}/src/fetcher/imap_client.py +0 -0
- {fetch2gmail-1.1.6 → fetch2gmail-1.1.7}/src/fetcher/log_buffer.py +0 -0
- {fetch2gmail-1.1.6 → fetch2gmail-1.1.7}/src/fetcher/run.py +0 -0
- {fetch2gmail-1.1.6 → fetch2gmail-1.1.7}/src/fetcher/state.py +0 -0
- {fetch2gmail-1.1.6 → fetch2gmail-1.1.7}/src/fetcher/ui_auth.py +0 -0
|
@@ -97,12 +97,13 @@ def _auth_callback(
|
|
|
97
97
|
|
|
98
98
|
cred_abs = cred_path.resolve()
|
|
99
99
|
tok_abs = token_path.resolve()
|
|
100
|
+
tok_name = tok_abs.name
|
|
100
101
|
html = f"""<!DOCTYPE html><html><head><meta charset="utf-8"><title>Token saved</title></head><body>
|
|
101
102
|
<h2>Token saved</h2>
|
|
102
|
-
<p><strong>
|
|
103
|
+
<p><strong>{tok_name}</strong> has been saved. Copy these two files to your Odroid (or other headless device):</p>
|
|
103
104
|
<ul>
|
|
104
105
|
<li><strong>credentials.json</strong> (from GCP)</li>
|
|
105
|
-
<li><strong>
|
|
106
|
+
<li><strong>{tok_name}</strong> (just saved at <code>{tok_abs}</code>)</li>
|
|
106
107
|
</ul>
|
|
107
108
|
<p>On the headless server (e.g. Debian, Odroid, Raspberry Pi), put both files in the <strong>data directory</strong> where Fetch2Gmail runs — the same folder as <code>config.json</code>, e.g. <code>/opt/fetch2gmail</code> or <code>/home/odroid/fetch2gmail</code>. See the README for setup.</p>
|
|
108
109
|
<p>You can close this window and stop the server (Ctrl+C).</p>
|
|
@@ -235,7 +235,21 @@ def _cmd_auth(args: argparse.Namespace) -> None:
|
|
|
235
235
|
from .auth_server import app
|
|
236
236
|
|
|
237
237
|
cred_path = Path(args.credentials).resolve()
|
|
238
|
-
|
|
238
|
+
# If the user did not override --token (still default "token.json"), automatically pick
|
|
239
|
+
# token.json, token2.json, token3.json, ... in the current directory, so additional
|
|
240
|
+
# accounts are easy to add without manually specifying --token.
|
|
241
|
+
if args.token == "token.json":
|
|
242
|
+
base_dir = Path.cwd()
|
|
243
|
+
idx = 0
|
|
244
|
+
while True:
|
|
245
|
+
name = "token.json" if idx == 0 else f"token{idx + 1}.json"
|
|
246
|
+
candidate = base_dir / name
|
|
247
|
+
if not candidate.exists():
|
|
248
|
+
token_path = candidate
|
|
249
|
+
break
|
|
250
|
+
idx += 1
|
|
251
|
+
else:
|
|
252
|
+
token_path = Path(args.token).resolve()
|
|
239
253
|
if not cred_path.exists():
|
|
240
254
|
print(f"Credentials file not found: {cred_path}", file=sys.stderr)
|
|
241
255
|
print("Download credentials.json from Google Cloud (OAuth client, Web application).", file=sys.stderr)
|
|
@@ -252,8 +266,9 @@ def _cmd_auth(args: argparse.Namespace) -> None:
|
|
|
252
266
|
webbrowser.open(url)
|
|
253
267
|
|
|
254
268
|
threading.Thread(target=open_browser, daemon=True).start()
|
|
255
|
-
|
|
256
|
-
print("
|
|
269
|
+
token_name = token_path.name
|
|
270
|
+
print(f"Opening {url} in your browser. Sign in with Google; {token_name} will be saved to {token_path}")
|
|
271
|
+
print(f"Then copy credentials.json and {token_name} to your Odroid. Press Ctrl+C when done.")
|
|
257
272
|
import uvicorn
|
|
258
273
|
uvicorn.run(app, host="127.0.0.1", port=args.port, log_level="warning")
|
|
259
274
|
|
|
@@ -1046,43 +1046,88 @@ _APP_JS = r"""
|
|
|
1046
1046
|
if (!wrap) return;
|
|
1047
1047
|
var accounts = ensureGmailAccounts(c);
|
|
1048
1048
|
if (!accounts.length) {
|
|
1049
|
-
wrap.innerHTML = '<p class
|
|
1049
|
+
wrap.innerHTML = '<p class=\"error\">No Gmail accounts configured.</p>';
|
|
1050
1050
|
return;
|
|
1051
1051
|
}
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
html
|
|
1062
|
-
html += '<
|
|
1063
|
-
html += '<
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1052
|
+
// Enrich with Gmail email addresses by looking at token*.json files.
|
|
1053
|
+
api('/api/gmail/discover-tokens').then(function(tokens) {
|
|
1054
|
+
var emailByToken = {};
|
|
1055
|
+
if (Array.isArray(tokens)) {
|
|
1056
|
+
for (var i = 0; i < tokens.length; i++) {
|
|
1057
|
+
var t = tokens[i];
|
|
1058
|
+
if (t && t.token_path) emailByToken[t.token_path] = t.email || '';
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
var html = '<div style=\"margin-top:0.5rem;\">';
|
|
1062
|
+
html += '<table style=\"width:100%; border-collapse:collapse;\">';
|
|
1063
|
+
html += '<tr><th style=\"text-align:left; font-weight:600; padding:4px 0;\">Account</th><th style=\"text-align:left; font-weight:600; padding:4px 0;\">Token</th><th style=\"text-align:left; font-weight:600; padding:4px 0;\">Gmail account</th><th></th></tr>';
|
|
1064
|
+
for (var j = 0; j < accounts.length; j++) {
|
|
1065
|
+
var a = accounts[j];
|
|
1066
|
+
var token = (a.token_path || '').replace(/</g,'<').replace(/>/g,'>');
|
|
1067
|
+
var email = emailByToken[a.token_path || ''] || '';
|
|
1068
|
+
var emailDisplay = email ? email.replace(/</g,'<').replace(/>/g,'>') : '(unknown)';
|
|
1069
|
+
html += '<tr style=\"border-top:1px solid #eee;\">';
|
|
1070
|
+
html += '<td style=\"padding:6px 0;\">#' + (j + 1) + (j === 0 ? ' (primary)' : '') + '</td>';
|
|
1071
|
+
html += '<td style=\"padding:6px 0;\"><code>' + token + '</code></td>';
|
|
1072
|
+
html += '<td style=\"padding:6px 0; white-space:nowrap;\">' + emailDisplay + '</td>';
|
|
1073
|
+
html += '<td style=\"padding:6px 0; text-align:right;\">' + (j === 0 ? '' : '<button type=\"button\" data-gdel=\"' + j + '\">Delete</button>') + '</td>';
|
|
1074
|
+
html += '</tr>';
|
|
1075
|
+
}
|
|
1076
|
+
html += '</table>';
|
|
1077
|
+
html += '<p class=\"hint\" style=\"font-size:0.85rem; color:#666; margin:0.5rem 0 0;\">Deleting a secondary account also deletes its token file (e.g. <code>token2.json</code>).</p>';
|
|
1078
|
+
html += '</div>';
|
|
1079
|
+
wrap.innerHTML = html;
|
|
1080
|
+
// Wire delete buttons
|
|
1081
|
+
var btns = wrap.querySelectorAll('button[data-gdel]');
|
|
1082
|
+
for (var k = 0; k < btns.length; k++) {
|
|
1083
|
+
btns[k].onclick = function(ev) {
|
|
1084
|
+
var idx = parseInt(ev.target.getAttribute('data-gdel'), 10);
|
|
1085
|
+
if (!confirm('Delete Gmail account #' + (idx + 1) + '?\\n\\nThis will remove it from config and delete its token file.')) return;
|
|
1086
|
+
del('/api/gmail/accounts', { index: idx }).then(function(r) {
|
|
1087
|
+
document.getElementById('status').textContent = r.message || 'Account deleted.';
|
|
1088
|
+
document.getElementById('status').className = 'status';
|
|
1089
|
+
return loadConfig().then(function(cc) { if (cc) { renderGmailAccounts(cc); } });
|
|
1090
|
+
}).catch(function(e) {
|
|
1091
|
+
document.getElementById('status').textContent = 'Error: ' + (typeof e.detail === 'string' ? e.detail : (e.detail && e.detail.detail) || e.message || 'Delete failed');
|
|
1092
|
+
document.getElementById('status').className = 'error';
|
|
1093
|
+
});
|
|
1094
|
+
};
|
|
1095
|
+
}
|
|
1096
|
+
}).catch(function() {
|
|
1097
|
+
// Fallback: render without email info if discover-tokens fails.
|
|
1098
|
+
var html = '<div style=\"margin-top:0.5rem;\">';
|
|
1099
|
+
html += '<table style=\"width:100%; border-collapse:collapse;\">';
|
|
1100
|
+
html += '<tr><th style=\"text-align:left; font-weight:600; padding:4px 0;\">Account</th><th style=\"text-align:left; font-weight:600; padding:4px 0;\">Token</th><th></th></tr>';
|
|
1101
|
+
for (var j = 0; j < accounts.length; j++) {
|
|
1102
|
+
var a = accounts[j];
|
|
1103
|
+
var token = (a.token_path || '').replace(/</g,'<').replace(/>/g,'>');
|
|
1104
|
+
html += '<tr style=\"border-top:1px solid #eee;\">';
|
|
1105
|
+
html += '<td style=\"padding:6px 0;\">#' + (j + 1) + (j === 0 ? ' (primary)' : '') + '</td>';
|
|
1106
|
+
html += '<td style=\"padding:6px 0;\"><code>' + token + '</code></td>';
|
|
1107
|
+
html += '<td style=\"padding:6px 0; text-align:right;\">' + (j === 0 ? '' : '<button type=\"button\" data-gdel=\"' + j + '\">Delete</button>') + '</td>';
|
|
1108
|
+
html += '</tr>';
|
|
1109
|
+
}
|
|
1110
|
+
html += '</table>';
|
|
1111
|
+
html += '<p class=\"hint\" style=\"font-size:0.85rem; color:#666; margin:0.5rem 0 0;\">Deleting a secondary account also deletes its token file (e.g. <code>token2.json</code>).</p>';
|
|
1112
|
+
html += '</div>';
|
|
1113
|
+
wrap.innerHTML = html;
|
|
1114
|
+
// Wire delete buttons in fallback as well.
|
|
1115
|
+
var btns = wrap.querySelectorAll('button[data-gdel]');
|
|
1116
|
+
for (var k = 0; k < btns.length; k++) {
|
|
1117
|
+
btns[k].onclick = function(ev) {
|
|
1118
|
+
var idx = parseInt(ev.target.getAttribute('data-gdel'), 10);
|
|
1119
|
+
if (!confirm('Delete Gmail account #' + (idx + 1) + '?\\n\\nThis will remove it from config and delete its token file.')) return;
|
|
1120
|
+
del('/api/gmail/accounts', { index: idx }).then(function(r) {
|
|
1121
|
+
document.getElementById('status').textContent = r.message || 'Account deleted.';
|
|
1122
|
+
document.getElementById('status').className = 'status';
|
|
1123
|
+
return loadConfig().then(function(cc) { if (cc) { renderGmailAccounts(cc); } });
|
|
1124
|
+
}).catch(function(e) {
|
|
1125
|
+
document.getElementById('status').textContent = 'Error: ' + (typeof e.detail === 'string' ? e.detail : (e.detail && e.detail.detail) || e.message || 'Delete failed');
|
|
1126
|
+
document.getElementById('status').className = 'error';
|
|
1127
|
+
});
|
|
1128
|
+
};
|
|
1129
|
+
}
|
|
1130
|
+
});
|
|
1086
1131
|
}
|
|
1087
1132
|
function loadConfig() {
|
|
1088
1133
|
return api('/api/config').then(function(c) {
|
|
@@ -1118,7 +1163,21 @@ _APP_JS = r"""
|
|
|
1118
1163
|
document.getElementById('gmailStatus').innerHTML = c.gmail_connected ? '<span class="ok">Gmail connected</span>' : '<span class="error">Not connected (add token.json from fetch2gmail auth)</span>';
|
|
1119
1164
|
document.getElementById('gmailEmail').textContent = '';
|
|
1120
1165
|
if (c.gmail_connected) {
|
|
1121
|
-
api('/api/gmail/
|
|
1166
|
+
api('/api/gmail/discover-tokens').then(function(tokens) {
|
|
1167
|
+
if (!Array.isArray(tokens) || !tokens.length) return;
|
|
1168
|
+
var emails = [];
|
|
1169
|
+
for (var i = 0; i < tokens.length; i++) {
|
|
1170
|
+
if (tokens[i].email) emails.push(tokens[i].email);
|
|
1171
|
+
}
|
|
1172
|
+
if (!emails.length) return;
|
|
1173
|
+
var uniq = [];
|
|
1174
|
+
var seen = {};
|
|
1175
|
+
for (var j = 0; j < emails.length; j++) {
|
|
1176
|
+
var e = emails[j];
|
|
1177
|
+
if (!seen[e]) { seen[e] = true; uniq.push(e); }
|
|
1178
|
+
}
|
|
1179
|
+
document.getElementById('gmailEmail').textContent = 'Connected as ' + uniq.join(', ');
|
|
1180
|
+
}).catch(function() {});
|
|
1122
1181
|
}
|
|
1123
1182
|
renderGmailAccounts(c);
|
|
1124
1183
|
return c;
|
|
@@ -1268,15 +1327,6 @@ _APP_JS = r"""
|
|
|
1268
1327
|
document.getElementById('gmail_use_label').onchange = function() {
|
|
1269
1328
|
document.getElementById('gmail_label_row').style.display = this.checked ? 'block' : 'none';
|
|
1270
1329
|
};
|
|
1271
|
-
// Keep legacy "Label name" and table row 0 in sync (table is source of truth on save).
|
|
1272
|
-
document.getElementById('gmail_label').addEventListener('input', function() {
|
|
1273
|
-
var first = document.querySelector('#gmailAccounts input[data-glabel="0"]');
|
|
1274
|
-
if (first) first.value = this.value;
|
|
1275
|
-
});
|
|
1276
|
-
document.getElementById('gmailAccounts').addEventListener('input', function(ev) {
|
|
1277
|
-
var el = ev.target;
|
|
1278
|
-
if (el.getAttribute('data-glabel') === '0') document.getElementById('gmail_label').value = el.value;
|
|
1279
|
-
});
|
|
1280
1330
|
document.getElementById('btnSave').onclick = function() {
|
|
1281
1331
|
// Read current accounts from UI (labels only editable here).
|
|
1282
1332
|
var currentAccounts = null;
|
|
@@ -1298,18 +1348,18 @@ _APP_JS = r"""
|
|
|
1298
1348
|
};
|
|
1299
1349
|
var pw = document.getElementById('imap_password').value;
|
|
1300
1350
|
if (pw) body.imap_password = pw;
|
|
1301
|
-
// Merge updated
|
|
1351
|
+
// Merge updated settings into gmail_accounts and save canonical list.
|
|
1302
1352
|
api('/api/config').then(function(c) {
|
|
1303
1353
|
var accounts = ensureGmailAccounts(c);
|
|
1304
|
-
var
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
}
|
|
1309
|
-
// Table is single source of truth (legacy field is synced into table row 0 via listener below).
|
|
1310
|
-
// also apply global label toggle to all accounts (simple, predictable)
|
|
1354
|
+
var useLabel = document.getElementById('gmail_use_label').checked;
|
|
1355
|
+
var globalLabel = document.getElementById('gmail_label').value || 'ISP Mail';
|
|
1356
|
+
// Apply global label toggle to all accounts; apply global label NAME only to primary
|
|
1357
|
+
// account so per-account labels (e.g. email-based) are not overwritten.
|
|
1311
1358
|
for (var k = 0; k < accounts.length; k++) {
|
|
1312
|
-
accounts[k].use_label =
|
|
1359
|
+
accounts[k].use_label = useLabel;
|
|
1360
|
+
if (k === 0) {
|
|
1361
|
+
accounts[k].label = globalLabel;
|
|
1362
|
+
}
|
|
1313
1363
|
}
|
|
1314
1364
|
body.gmail_accounts = accounts;
|
|
1315
1365
|
return put('/api/config', body);
|
|
@@ -1376,7 +1426,7 @@ _APP_JS = r"""
|
|
|
1376
1426
|
}
|
|
1377
1427
|
btnCancel.onclick = closePanel;
|
|
1378
1428
|
|
|
1379
|
-
|
|
1429
|
+
api('/api/gmail/discover-tokens').then(function(tokens) {
|
|
1380
1430
|
var available = tokens.filter(function(t) { return !t.in_use && t.token_path; });
|
|
1381
1431
|
if (!available.length) {
|
|
1382
1432
|
msg.textContent = 'No unused token*.json files found in the app folder. Run: fetch2gmail auth --token token2.json';
|
|
@@ -1401,11 +1451,16 @@ _APP_JS = r"""
|
|
|
1401
1451
|
btnOk.disabled = true;
|
|
1402
1452
|
msg.textContent = 'Adding account...';
|
|
1403
1453
|
msg.className = 'status';
|
|
1454
|
+
var chosenEmail = '';
|
|
1455
|
+
for (var i = 0; i < available.length; i++) {
|
|
1456
|
+
if (available[i].token_path === chosen) { chosenEmail = available[i].email || ''; break; }
|
|
1457
|
+
}
|
|
1404
1458
|
api('/api/config').then(function(c) {
|
|
1405
1459
|
var accounts = ensureGmailAccounts(c);
|
|
1406
1460
|
accounts.push({
|
|
1407
1461
|
use_label: document.getElementById('gmail_use_label').checked,
|
|
1408
|
-
label:
|
|
1462
|
+
// Default label for new accounts: Gmail email if known; otherwise fall back to global label or ISP Mail.
|
|
1463
|
+
label: (chosenEmail || document.getElementById('gmail_label').value || 'ISP Mail'),
|
|
1409
1464
|
credentials_path: (accounts[0] && accounts[0].credentials_path) ? accounts[0].credentials_path : 'credentials.json',
|
|
1410
1465
|
token_path: chosen
|
|
1411
1466
|
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|