function extractAllEmailSubmissions() {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
sheet.clear();
sheet.appendRow(['Name', 'USN', 'Section', 'Email']);
const threads = GmailApp.getInboxThreads(0, 200);
let added = 0;
threads.forEach(thread => {
const msg = thread.getMessages().pop();
const body = msg.getPlainBody();
const from = msg.getFrom();
const nameMatch = body.match(/Name\s*[:\-]\s*(.+)/i);
const usnMatch = body.match(/USN\s*[:\-]\s*([A-Za-z0-9]+)/i);
const sectionMatch = body.match(/Section\s*[:\-]\s*([A-Za-z0-9]+)/i);
const name = nameMatch ? nameMatch[1].trim() : '';
const usn = usnMatch ? usnMatch[1].trim().toUpperCase() : '';
const section = sectionMatch ? sectionMatch[1].trim().toUpperCase() : '';
if (name || usn) {
sheet.appendRow([name, usn, section, from]);
added++;
}
});
SpreadsheetApp.flush();
SpreadsheetApp.getUi().alert('Done! ' + added + ' submissions logged.');
}