postalsys / emailengine

Headless email client
https://emailengine.app/
Other
1.9k stars 169 forks source link

Outlook - wait for mailbox to be created #462

Closed Jivings closed 1 month ago

Jivings commented 1 month ago

Currently if you do an operation immediately after creating a mailbox then it fails with a 404 as the mailbox doesn't yet exist. If we wait a second before the second operation then it works fine.

So maybe we need to check a mailbox exists after creation with a backoff :)

Code to recreate:

import 'dotenv/config.js';

import axios from 'axios';

const url = process.env.URL
const key = process.env.API_KEY;

const response = await axios({
  method: 'POST',
  url: `${url}/v1/account/6e8b6c25-3075-4d54-9139-9aed0b83af3c/mailbox`,
  data: {
    path: ['mailbox-test']
  },
  params: {},
  headers: {
    Authorization: `Bearer ${key}`
  },
  httpsAgent
});
// will always be 200
console.log(response.status);

const response2 = await axios({
  method: 'GET',
  url: `${url}/v1/account/6e8b6c25-3075-4d54-9139-9aed0b83af3c/messages`,
  params: {
    path: 'mailbox-test'
  },
  headers: {
    Authorization: `Bearer ${key}`
  },
  httpsAgent
});

// will be 404, but 200 if waiting a few seconds
console.log(response2.status);
andris9 commented 1 month ago

Yes, the behavior depends on the specific backend and how changes are propagated by the mail servers. When EmailEngine returns a response to an API request, it indicates that it has received confirmation from the mail backend. However, this does not guarantee that the changes are immediately or universally available across all clients or services. There may be a delay before the new mailbox folders are accessible.