Tidy stale comments and duplicated helpers
Comments carried over from web_server (CVLayout.vue, messageResolver, the Spotify token code) and ones outdated by later changes (the email window now anchors on ReceivedAt, failed emails are retried) are corrected. truncateRunes had a copy in handlers and in services; there is now one, services.TruncateRunes. cleanEmailBody's regexes are compiled once, a status check that could never fire is gone, and api.js loses its unused put/patch helpers. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -74,8 +74,6 @@ type EmailSyncService struct {
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
// Microsoft Graph API response types
|
||||
|
||||
// Microsoft Graph API response types. The IMAP backend parses raw RFC822
|
||||
// messages into these same structs (see parseRawEmail) so that everything
|
||||
// downstream of fetchEmails is backend-agnostic.
|
||||
@@ -177,8 +175,8 @@ var statusOrder = map[string]int{
|
||||
// Token persistence
|
||||
|
||||
// SaveMSGraphToken persists an OAuth token to disk with 0600 permissions.
|
||||
// Like the Spotify equivalent it copies into a local struct so the on-disk
|
||||
// shape does not depend on the oauth2 package's own JSON tags.
|
||||
// It copies into a local struct so the on-disk shape does not depend on the
|
||||
// oauth2 package's own JSON tags.
|
||||
func SaveMSGraphToken(path string, tok *oauth2.Token) error {
|
||||
data := struct {
|
||||
AccessToken string `json:"access_token"`
|
||||
@@ -450,7 +448,6 @@ func (s *EmailSyncService) SyncEmails(ctx context.Context) error {
|
||||
since = oldestRetryable.ReceivedAt
|
||||
}
|
||||
|
||||
// Fetch emails from Microsoft Graph
|
||||
emails, err := s.fetchEmails(ctx, since)
|
||||
if err != nil {
|
||||
return fmt.Errorf("fetching emails: %w", err)
|
||||
@@ -767,10 +764,6 @@ func (s *EmailSyncService) createJobApplication(analysis *EmailAnalysis) (string
|
||||
}
|
||||
}
|
||||
|
||||
if app.Status == "" {
|
||||
app.Status = "applied"
|
||||
}
|
||||
|
||||
if err := s.DB.Create(&app).Error; err != nil {
|
||||
return "", nil, fmt.Errorf("creating job application: %w", err)
|
||||
}
|
||||
@@ -827,6 +820,13 @@ func (s *EmailSyncService) updateJobApplication(existing *models.JobApplication,
|
||||
return "updated", &existing.ID, nil
|
||||
}
|
||||
|
||||
// Whitespace patterns for cleanEmailBody. Tags are stripped with htmlAnyTag
|
||||
// (job_sources.go).
|
||||
var (
|
||||
emailSpaces = regexp.MustCompile(`[ \t]+`)
|
||||
emailBlankRuns = regexp.MustCompile(`\n{3,}`)
|
||||
)
|
||||
|
||||
// cleanEmailBody reduces an email body to plain-ish text before it is sent to
|
||||
// the classifier, cutting token cost and noise.
|
||||
//
|
||||
@@ -839,8 +839,7 @@ func cleanEmailBody(content string, contentType string) string {
|
||||
|
||||
if strings.EqualFold(contentType, "html") {
|
||||
// Strip HTML tags
|
||||
tagRegex := regexp.MustCompile(`<[^>]*>`)
|
||||
text = tagRegex.ReplaceAllString(text, " ")
|
||||
text = htmlAnyTag.ReplaceAllString(text, " ")
|
||||
|
||||
// Decode common HTML entities
|
||||
replacer := strings.NewReplacer(
|
||||
@@ -856,10 +855,8 @@ func cleanEmailBody(content string, contentType string) string {
|
||||
}
|
||||
|
||||
// Collapse whitespace
|
||||
spaceRegex := regexp.MustCompile(`[ \t]+`)
|
||||
text = spaceRegex.ReplaceAllString(text, " ")
|
||||
nlRegex := regexp.MustCompile(`\n{3,}`)
|
||||
text = nlRegex.ReplaceAllString(text, "\n\n")
|
||||
text = emailSpaces.ReplaceAllString(text, " ")
|
||||
text = emailBlankRuns.ReplaceAllString(text, "\n\n")
|
||||
text = strings.TrimSpace(text)
|
||||
|
||||
// Cut everything from the first signature marker onwards. The idx > 0
|
||||
@@ -953,8 +950,7 @@ func parseReceivedAt(raw string) time.Time {
|
||||
|
||||
// saveProcessed writes the outcome of an attempt: updating the existing row
|
||||
// when this was a retry, inserting when it is the first attempt. Update is
|
||||
// used rather than Save so the row keeps its original CreatedAt, which the
|
||||
// fetch window depends on.
|
||||
// used rather than Save so the row keeps its original CreatedAt.
|
||||
func (s *EmailSyncService) saveProcessed(found bool, existing, record *models.ProcessedEmail) {
|
||||
var err error
|
||||
if found {
|
||||
|
||||
Reference in New Issue
Block a user