Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1: move doesn't move emails in Gmail IMAP #548

Open
captv89 opened this issue Oct 4, 2023 · 0 comments
Open

v1: move doesn't move emails in Gmail IMAP #548

captv89 opened this issue Oct 4, 2023 · 0 comments

Comments

@captv89
Copy link

captv89 commented Oct 4, 2023

I have the below function to move the mails to a Destination Folder/mailbox

// moveEmail moves an email to the specified mailbox folder.
func moveEmail(c *client.Client, msg *imap.Message, destMailbox string) error {
	// Check if the destination mailbox exists else create it
	if _, err := c.Select(destMailbox, false); err != nil {
		log.Printf("Destination mailbox not found: %v", err)
		log.Printf("Creating destination mailbox: %s", destMailbox)
		if err := c.Create(destMailbox); err != nil {
			log.Printf("Error creating destination mailbox: %v", err)
			return err
		}
	}

	// Move the email from inbox to destination mailbox
	seqSet := new(imap.SeqSet)
	seqSet.AddNum(msg.Uid)
	log.Printf("Moving email with UID: %d to %s", msg.Uid, destMailbox)

	err := c.Move(seqSet, destMailbox)
	if err != nil {
		log.Printf("Error moving email: %v", err)
		return err
	}
	return nil
}

However, the c.Move doesn't perform the action, the mails remain in the same Label (as they say in Gmail) / mailbox.

moveEmail function is called from another function as below:

// Move to the "Recognised" mailbox folder
if err := moveEmail(client, msg, "Recognised"); err != nil {
  log.Printf("Error moving email: %v\n", err)
  return err
}

Here msg is *imap.Message obtained as below

seqset := new(imap.SeqSet)
seqset.AddRange(1, inbox.Messages)

items := []imap.FetchItem{imap.FetchEnvelope, imap.FetchUid}

messages := make(chan *imap.Message, inbox.Messages)

if err := client.Fetch(seqset, items, messages); err != nil {
log.Fatal(err)
}

// Iterate through the list of messages and move them based on the subject
for msg := range messages {
// Contains some checks and then finally the call to moveEmails
}
@emersion emersion changed the title Move doesn't move emails in Gmail IMAP v1: move doesn't move emails in Gmail IMAP Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant