Added skills, shortcuts, and bugifixes++
This commit is contained in:
@@ -130,31 +130,37 @@ final class EmailService {
|
||||
// Search for ALL unseen emails first
|
||||
let allUnseenUIDs = try await client.searchUnseen()
|
||||
|
||||
// Remove UIDs that are no longer unseen (emails were deleted/marked read)
|
||||
checkedUIDs = checkedUIDs.intersection(Set(allUnseenUIDs))
|
||||
|
||||
// Check each email for the subject identifier
|
||||
for uid in allUnseenUIDs {
|
||||
if !checkedUIDs.contains(uid) {
|
||||
checkedUIDs.insert(uid)
|
||||
// Skip if we've already checked this UID (for non-matching emails only)
|
||||
if checkedUIDs.contains(uid) {
|
||||
continue
|
||||
}
|
||||
|
||||
do {
|
||||
let email = try await client.fetchEmail(uid: uid)
|
||||
do {
|
||||
let email = try await client.fetchEmail(uid: uid)
|
||||
|
||||
// Check if email has the correct subject identifier
|
||||
if email.subject.contains(settings.emailSubjectIdentifier) {
|
||||
// Valid email - process it
|
||||
log.info("New email found: \(email.subject) from \(email.from)")
|
||||
// Check if email has the correct subject identifier
|
||||
if email.subject.contains(self.settings.emailSubjectIdentifier) {
|
||||
// Valid email - process it (don't add to checkedUIDs, handler will delete it)
|
||||
log.info("Found matching email: \(email.subject) from \(email.from)")
|
||||
|
||||
// Call callback on main thread
|
||||
await MainActor.run {
|
||||
onNewEmail?(email)
|
||||
}
|
||||
} else {
|
||||
// Wrong subject - delete it
|
||||
log.warning("Deleting email without subject identifier: \(email.subject) from \(email.from)")
|
||||
try await client.deleteEmail(uid: uid)
|
||||
// Call callback on main thread
|
||||
await MainActor.run {
|
||||
onNewEmail?(email)
|
||||
}
|
||||
} catch {
|
||||
log.error("Failed to fetch/process email \(uid): \(error.localizedDescription)")
|
||||
} else {
|
||||
// Wrong subject - delete it and remember we checked it
|
||||
log.warning("Deleting email without subject identifier: \(email.subject) from \(email.from)")
|
||||
try await client.deleteEmail(uid: uid)
|
||||
checkedUIDs.insert(uid) // Only track non-matching emails
|
||||
}
|
||||
} catch {
|
||||
log.error("Failed to fetch/process email \(uid): \(error.localizedDescription)")
|
||||
checkedUIDs.insert(uid) // Track failed emails to avoid retry loops
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user