diff --git a/TODO.md b/TODO.md index 5e83e99..09774aa 100644 --- a/TODO.md +++ b/TODO.md @@ -64,3 +64,4 @@ - [x] Fix IMAP folder creation, which does not work. - [ ] Give the sidebar (Inbox, Folders, etc.) more room so every item fits on screen: make the box scrollable with a slider, or remove or collapse less-used items. - [ ] Make labels work and add the ability to create more labels. +- [x] Fix created IMAP folders not showing in the mail rules folder list; only Inbox, Archive and Trash are shown. diff --git a/android/app/src/main/java/studio/daybreak/mail/EpMailPlugin.kt b/android/app/src/main/java/studio/daybreak/mail/EpMailPlugin.kt index bb90b52..546d2fa 100644 --- a/android/app/src/main/java/studio/daybreak/mail/EpMailPlugin.kt +++ b/android/app/src/main/java/studio/daybreak/mail/EpMailPlugin.kt @@ -497,8 +497,8 @@ class EpMailPlugin : Plugin() { require(action != "move" || !value.any { it == '\r' || it == '\n' || it == '\u0000' }) { "Mail rule ${index + 1} has an invalid destination folder." } - require(action != "move" || value in setOf("Inbox", "Archive", "Trash")) { - "Mail rule ${index + 1} must move messages to Inbox, Archive, or Trash." + require(action != "move" || value in setOf("Inbox", "Archive", "Trash") || AndroidMailService.isCustomFolder(value)) { + "Mail rule ${index + 1} must move messages to Inbox, Archive, Trash, or one of your folders." } result.put(JSONObject() .put("id", rule.optString("id").ifBlank { UUID.randomUUID().toString() }) diff --git a/desktop/main.cjs b/desktop/main.cjs index a47c7f9..4325fcc 100644 --- a/desktop/main.cjs +++ b/desktop/main.cjs @@ -294,8 +294,8 @@ function normalizeAccount(input) { if ((action === 'move' || action === 'label') && !value) { throw new Error(`Mail rule ${index + 1} needs a destination folder or label.`); } - if (action === 'move' && !['Inbox', 'Archive', 'Trash'].includes(value)) { - throw new Error(`Mail rule ${index + 1} must move messages to Inbox, Archive, or Trash.`); + if (action === 'move' && !['Inbox', 'Archive', 'Trash'].includes(value) && !value.startsWith(CUSTOM_FOLDER_PREFIX)) { + throw new Error(`Mail rule ${index + 1} must move messages to Inbox, Archive, Trash, or one of your folders.`); } return { id: String(rule.id || randomUUID()), senderContains, subjectContains, action, value }; }); diff --git a/mail-ui.js b/mail-ui.js index ace0b4c..52b5bfc 100644 --- a/mail-ui.js +++ b/mail-ui.js @@ -140,6 +140,16 @@ async function loadCustomFolders() { } catch {} } +// Destination options for the mail-rule folder picker: built-in folders plus the account's IMAP folders. +function ruleFolderSelect(selected = 'Inbox') { + const options = [['Inbox', 'Inbox'], ['Archive', 'Archive'], ['Trash', 'Trash'], ...customFolders.map(folder => [folder.id, folder.name])]; + if (!options.some(([value]) => value === selected)) { + options.push([selected, String(selected).replace(/^[^:]*:/, '') || selected]); + } + return ''; +} + // window.prompt() is not available in Electron, so ask for text in an in-app dialog. function askText(title, label, placeholder = '') { return new Promise(resolve => { @@ -206,7 +216,7 @@ function openMailAccount(existingAccount = null) { ${[['archive','Archive'],['move','Move to folder'],['label','Apply label'],['flag','Flag']].map(([value,label])=>``).join('')} ${rule.action==='move' - ? `` + ? `${ruleFolderSelect(rule.value)}` : ``} `).join(''); @@ -231,8 +241,8 @@ function openMailAccount(existingAccount = null) { const row = event.target.closest('.mail-rule-row'); const value = row.querySelector('.mail-rule-value'); if (event.target.value === 'move') { - const selected = ['Inbox', 'Archive', 'Trash'].includes(value.value) ? value.value : 'Inbox'; - value.outerHTML = ``; + const selected = value.value || 'Inbox'; + value.outerHTML = ruleFolderSelect(selected); } else if (value.tagName === 'SELECT') { value.outerHTML = ``; } diff --git a/package.json b/package.json index 94a70ff..d506f03 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,8 @@ "build:android-web": "node scripts/prepare-android-web.cjs", "android:sync": "npm run build:android-web && cap sync android", "android:open": "npm run android:sync && cap open android", - "android:apk": "npm run android:sync && node scripts/build-android-apk.cjs" + "android:apk": "npm run android:sync && node scripts/build-android-apk.cjs", + "build:all": "powershell -NoProfile -ExecutionPolicy Bypass -File scripts/build-all.ps1" }, "devDependencies": { "@capacitor/cli": "^8.5.2", diff --git a/scripts/build-all.ps1 b/scripts/build-all.ps1 new file mode 100644 index 0000000..4c1fbea --- /dev/null +++ b/scripts/build-all.ps1 @@ -0,0 +1,19 @@ +# Builds the Android APK and the Windows portable exe into .\release +$ErrorActionPreference = 'Stop' +Set-Location $PSScriptRoot\.. +$version = (Get-Content package.json -Raw | ConvertFrom-Json).version +if (-not $env:JAVA_HOME) { $env:JAVA_HOME = 'C:\Program Files\Android\Android Studio\jbr' } +if (-not $env:ANDROID_HOME) { $env:ANDROID_HOME = Join-Path $env:LOCALAPPDATA 'Android\Sdk' } +New-Item -ItemType Directory -Force release | Out-Null + +Write-Host "== Building APK $version ==" +npm run android:apk +if ($LASTEXITCODE) { throw 'APK build failed' } +Copy-Item android\app\build\outputs\apk\debug\app-debug.apk "release\ep-mail $version.apk" -Force + +Write-Host "== Building portable exe $version ==" +npm run dist:win:portable +if ($LASTEXITCODE) { throw 'Portable build failed' } + +Write-Host "`nDone:" +Get-ChildItem release | Where-Object { $_.Name -like "ep-mail $version.*" } | ForEach-Object { " $($_.FullName)" } \ No newline at end of file diff --git a/www/mail-ui.js b/www/mail-ui.js index ace0b4c..52b5bfc 100644 --- a/www/mail-ui.js +++ b/www/mail-ui.js @@ -140,6 +140,16 @@ async function loadCustomFolders() { } catch {} } +// Destination options for the mail-rule folder picker: built-in folders plus the account's IMAP folders. +function ruleFolderSelect(selected = 'Inbox') { + const options = [['Inbox', 'Inbox'], ['Archive', 'Archive'], ['Trash', 'Trash'], ...customFolders.map(folder => [folder.id, folder.name])]; + if (!options.some(([value]) => value === selected)) { + options.push([selected, String(selected).replace(/^[^:]*:/, '') || selected]); + } + return ''; +} + // window.prompt() is not available in Electron, so ask for text in an in-app dialog. function askText(title, label, placeholder = '') { return new Promise(resolve => { @@ -206,7 +216,7 @@ function openMailAccount(existingAccount = null) { ${[['archive','Archive'],['move','Move to folder'],['label','Apply label'],['flag','Flag']].map(([value,label])=>``).join('')} ${rule.action==='move' - ? `` + ? `${ruleFolderSelect(rule.value)}` : ``} `).join(''); @@ -231,8 +241,8 @@ function openMailAccount(existingAccount = null) { const row = event.target.closest('.mail-rule-row'); const value = row.querySelector('.mail-rule-value'); if (event.target.value === 'move') { - const selected = ['Inbox', 'Archive', 'Trash'].includes(value.value) ? value.value : 'Inbox'; - value.outerHTML = ``; + const selected = value.value || 'Inbox'; + value.outerHTML = ruleFolderSelect(selected); } else if (value.tagName === 'SELECT') { value.outerHTML = ``; }