/** * WooCow – My Account frontend JavaScript */ (function ($) { 'use strict'; if (!$('#woocow-account').length) return; const ajax = (action, data) => $.post(woocowAcct.ajax_url, { action, nonce: woocowAcct.nonce, ...data }); const notice = (msg, type = 'success') => { const $n = $('#woocow-acct-notices'); $n.html(`
`); setTimeout(() => $n.find('> div').fadeOut(400, function () { $(this).remove(); }), 5000); }; function esc(str) { return String(str).replace(/[&<>"']/g, m => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[m]); } function formatMB(bytes) { if (!bytes) return '0 MB'; const mb = bytes / 1024 / 1024; return mb >= 1024 ? (mb / 1024).toFixed(1) + ' GB' : mb.toFixed(0) + ' MB'; } // ── Load Mailboxes ──────────────────────────────────────────────────────── $(document).on('click', '.woocow-load-mailboxes', function () { const $panel = $(this).closest('.woocow-domain-panel'); const sid = $panel.data('server-id'); const domain = $panel.data('domain'); const $wrap = $panel.find('.woocow-mailboxes-wrap'); const $list = $panel.find('.woocow-mailboxes-list'); $(this).prop('disabled', true).text('Loading…'); $wrap.show(); $list.html('Fetching mailboxes…
'); ajax('woocow_acct_mailboxes', { server_id: sid, domain }).done(res => { $(this).prop('disabled', false).text('Refresh'); if (!res.success) { $list.html(`${esc(res.data)}
`); return; } const boxes = res.data.mailboxes || []; const webmail = res.data.webmail_url; if (!boxes.length) { $list.html('No mailboxes yet. Create one below.
'); return; } let html = ''; boxes.forEach(m => { const unlimited = (m.quota === 0 || m.quota === '0'); const pct = unlimited ? 0 : parseFloat(m.percent_in_use || 0); const used = formatMB(m.quota_used); const max = unlimited ? '∞' : formatMB(m.quota); const col = pct > 85 ? '#e74c3c' : pct > 60 ? '#f39c12' : '#27ae60'; html += `Loading aliases…
'); $wrap.slideDown(); ajax('woocow_acct_aliases', { server_id: sid, domain }).done(res => { if (!res.success) { $list.html(`${esc(res.data)}
`); return; } const aliases = res.data; if (!aliases.length) { $list.html('No aliases for this domain yet.
'); return; } let html = 'Loading quarantine…
'); $wrap.slideDown(); ajax('woocow_acct_quarantine', { server_id: sid, domain }).done(res => { if (!res.success) { $list.html(`${esc(res.data)}
`); return; } const msgs = res.data; if (!msgs.length) { $list.html('No quarantined messages for this domain.
'); return; } let html = `| From | To | Subject | Score | Date | |
|---|---|---|---|---|---|
| ${esc(m.sender)} | ${esc(m.rcpt)} | ${esc(m.subject)}${virus} | ${score} | ${esc(date)} |
To release a message to your inbox, use the link in your quarantine notification email or via Webmail.
'; $list.html(html); }); }); $(document).on('click', '.wc-q-del', function () { if (!confirm('Permanently delete this quarantined message?')) return; const $row = $(this).closest('tr'); ajax('woocow_acct_quarantine_delete', { server_id: $(this).data('server'), domain: $(this).data('domain'), qid: $(this).data('id'), }).done(res => { if (res.success) $row.fadeOut(300, function () { $(this).remove(); }); else alert('Delete failed: ' + res.data); }); }); // ── Spam Score ──────────────────────────────────────────────────────────── $(document).on('click', '.wc-spam-score-btn', function () { const $row = $(this).closest('.woocow-mailbox-row'); const sid = $(this).data('server'); const domain = $(this).data('domain'); const email = $(this).data('email'); const score = $(this).data('score'); const $existing = $row.find('.woocow-spam-panel'); if ($existing.length) { $existing.slideToggle(); return; } $row.append(`Lower = stricter. Default is 5. Emails above this score go to spam/quarantine.