client.imports()
Chaque méthode de cet espace de noms : sa signature, ses paramètres, ce qu'elle retourne et un exemple.
Méthodes
Bring an old mailbox across from a Google Takeout, .mbox, .eml, .zip or .tgz export, with progress and a list of what did not come through.
imports().listimports().listAllimports().iterateimports().getimports().createimports().uploadStateimports().uploadChunkimports().startimports().cancelimports().listFailuresimports().deleteUploadimports().importFilesimports().discoverMailboximports().checkMailboximports().connectMailboximports().resume
imports().list
List one page of mailbox imports
Page list(RequestOptions options)Returns one page of the imports in the workspace, newest first. Nothing is dropped from the history, so following nextCursor while hasMore is true reaches the very first import, and imports().listAll and imports().iterate do that walk for you. Each carries its status, the bytes read so far out of the total, and running counts of messages seen, imported, skipped as duplicates, left out by your options and not imported.
A key limited to particular addresses sees only imports into those addresses.
Paramètres
options.addressIdStringOnly imports into this address.
options.limitintRows per page, a whole number from 1 to 100. The server defaults to 25.
options.cursorStringThe
nextCursorfrom the previous page, an import id. One that names no import this key can see is a 400invalid_cursor.options.apiKeyStringOverrides the client's API key for this call only.
Retourne
A Page of import maps, with items, hasMore and nextCursor.
Exemple
Page page = client.imports().list(RequestOptions.create().limit(50)); for (Map<String, Object> item : page) { System.out.println(item.get("address") + " " + item.get("status") + " " + item.get("counts"));} if (page.hasMore()) { System.out.println("Next page: " + page.nextCursor());}Remarques
A GET is retried automatically on network failure and on 408, 429, 500, 502, 503 and 504 responses, up to the client's
maxRetries.
Aussi disponible dans
- API
GET /imports- TypeScript
imports.list()- Python
imports.list()- Ruby
imports.list- PHP
imports->list- Go
Imports.List- C#
Imports.ListAsync- CLI
openemail imports list
imports().listAll
Collect every mailbox import into one list
List<Map<String, Object>> listAll(RequestOptions options)Follows nextCursor from page to page and returns every import in the workspace, newest first, narrowed to one address when addressId is given. A key limited to particular addresses sees only imports into those addresses.
Paramètres
options.addressIdStringOnly imports into this address.
options.limitintPage size per request, from 1 to 100, defaulting to 25 on the server.
options.cursorStringAn import id to start after, skipping everything newer.
options.apiKeyStringOverrides the client's API key for every page of this walk.
Retourne
A list of import maps holding every import across all pages.
Exemple
List<Map<String, Object>> imports = client.imports().listAll(); for (Map<String, Object> all : imports) { System.out.println(all.get("id") + " " + all.get("status"));}Remarques
A failure on any page throws out of the whole call, and none of the pages already read are returned.
Aussi disponible dans
- API
GET /imports- TypeScript
imports.listAll()- Python
imports.list_all()- Ruby
imports.list_all- PHP
imports->listAll- Go
Imports.ListAll- C#
Imports.ListAllAsync
imports().iterate
Stream mailbox imports one at a time
PagedIterable iterate(RequestOptions options)Returns a PagedIterable that yields imports one at a time, newest first, and requests the next page only once the current one is used up. Breaking out of the for stops the requests.
Paramètres
options.addressIdStringOnly imports into this address.
options.limitintPage size per request, from 1 to 100, defaulting to 25 on the server.
options.cursorStringAn import id to start after, skipping everything newer.
options.apiKeyStringOverrides the client's API key for every page of this walk.
Retourne
A PagedIterable that yields one import map per step.
Exemple
for (Map<String, Object> item : client.imports().iterate(RequestOptions.of("addressId", "addr_2b7e"))) { System.out.println(item.get("status") + " " + item.get("id") + " " + item.get("counts"));}Remarques
The generator is lazy, so an abandoned loop costs only the pages you consumed.
Aussi disponible dans
- API
GET /imports- TypeScript
imports.iterate()- Python
imports.iterate()- Ruby
imports.iterate- PHP
imports->iterate- Go
Imports.Iterate- C#
Imports.IterateAsync
imports().get
Read one mailbox import
Map<String, Object> get(String id, RequestOptions options)Returns one import with its status, byte progress and counts. Poll it while status is queued or running. It settles on completed, failed or cancelled.
An id from another workspace answers exactly like one that never existed, with 404.
Paramètres
idStringObligatoireImport id,
imp_followed by 24 hex characters.options.apiKeyStringOverrides the client's API key for this call only.
Retourne
A map with id, addressId, address, status, options, files, formats, chunkBytes, totalBytes, processedBytes, counts, labelsCreated, labelsSkipped, lastError, uploadDeleted, createdAt, startedAt and finishedAt.
Exemple
Map<String, Object> item = client.imports().get("imp_3f9c2a7b1e4d8f60a5c7b92d"); System.out.println(item.get("status") + " " + item.get("processedBytes") + " " + item.get("totalBytes"));Remarques
lastErroris set only whenstatusisfailed.
Aussi disponible dans
- API
GET /imports/{id}- TypeScript
imports.get()- Python
imports.get()- Ruby
imports.get- PHP
imports->get- Go
Imports.Get- C#
Imports.GetAsync- CLI
openemail imports get
imports().create
Create a mailbox import and get its upload plan
Map<String, Object> create(Map<String, Object> body, RequestOptions options)Creates an import into one address of the workspace and returns it with status set to uploading. Each file is uploaded in parts of chunkBytes bytes, files[i].chunks of them, through imports().uploadChunk, and imports().start then queues the import.
The import reads Google Takeout archives, .mbox files from Apple Mail, Thunderbird and most desktop apps, .eml files, and .zip or .tgz archives holding any of those, up to 100 GB a file and 50 files an import. Threads, dates and labels come across. Imported mail is quiet: it runs no rules, forwards, notifications, summaries or webhooks.
imports().importFiles does create, upload and start in one call.
Paramètres
body.addressIdStringObligatoireThe address the mail belongs to. It must be an address this workspace owns and this key may act for.
body.filesList<Map<String, Object>>ObligatoireEach file as a map with
nameandbytes, its size, 1 to 50 of them, each at most 100 GB.body.options.keepInboxbooleanDefault true: mail that was in the old inbox lands in Inbox with its unread state. False files everything under Archive.
body.options.includeSpambooleanDefault false.
body.options.includeTrashbooleanDefault false.
options.apiKeyStringOverrides the client's API key for this call only.
Retourne
A map for the import with status set to uploading, chunkBytes and each file's chunks.
Exemple
Map<String, Object> item = client.imports().create(Body.of( "addressId", "addr_2b7e", "files", List.of(Body.of("name", "takeout-001.zip", "bytes", 2147483648L)))); System.out.println(item.get("chunkBytes") + " " + item.get("files"));Remarques
An address with an import already queued or running is 409
already_running.Not retried automatically.
Aussi disponible dans
- API
POST /imports- TypeScript
imports.create()- Python
imports.create()- Ruby
imports.create- PHP
imports->create- Go
Imports.Create- C#
Imports.CreateAsync- CLI
openemail imports create
imports().uploadState
See which parts of the upload have arrived
Map<String, Object> uploadState(String id, RequestOptions options)For each file, the indexes of the parts already stored, so an interrupted upload sends only what is missing. Empty once the import has left the uploading state.
Paramètres
idStringObligatoireImport id,
imp_followed by 24 hex characters.options.apiKeyStringOverrides the client's API key for this call only.
Retourne
A map with received, one sorted list of part indexes per file.
Exemple
Map<String, Object> state = client.imports().uploadState("imp_3f9c2a7b1e4d8f60a5c7b92d"); System.out.println(state.get("received"));Aussi disponible dans
imports().uploadChunk
Upload one part of an import file
Map<String, Object> uploadChunk(String id, int file, int chunk, byte[] data, RequestOptions options)Stores one part of file file: the bytes from chunk * chunkBytes up to the next part. Every part is exactly chunkBytes long except the last, and a part of the wrong length is 400 bad_chunk. Sending a part again replaces it, so a failed part can simply be retried.
Paramètres
idStringObligatoireImport id,
imp_followed by 24 hex characters.fileintObligatoireThe file index, in the order given to
imports().create.chunkintObligatoireThe part index, from 0.
databyte[]ObligatoireThe part as a byte array. All of it is sent, so pass the part alone rather than the whole file.
options.apiKeyStringOverrides the client's API key for this call only.
Retourne
A map echoing file, chunk and the bytes stored.
Exemple
byte[] bytes = Files.readAllBytes(Path.of("mailbox.mbox"));Map<String, Object> item = client.imports().create(Body.of( "addressId", "addr_5d1c9e3a7b2f4e60a8c1d3b9", "files", List.of(Body.of("name", "mailbox.mbox", "bytes", bytes.length))));int chunkBytes = ((Number) item.get("chunkBytes")).intValue(); for (int chunk = 0; chunk * chunkBytes < bytes.length; chunk += 1) { byte[] part = Arrays.copyOfRange(bytes, chunk * chunkBytes, Math.min(bytes.length, (chunk + 1) * chunkBytes)); Map<String, Object> stored = client.imports().uploadChunk((String) item.get("id"), 0, chunk, part); System.out.println("Part " + stored.get("chunk") + ": " + stored.get("bytes") + " bytes");} client.imports().start((String) item.get("id"));Remarques
Retried automatically on network failure and on 408, 429, 500, 502, 503 and 504 responses, since a repeated part replaces itself.
Aussi disponible dans
imports().start
Queue an import once its files are uploaded
Map<String, Object> start(String id, RequestOptions options)Checks that every part of every file has arrived, recognises each file's format and queues the import. A file still missing parts is 412 missing_chunks, and a file that is not an archive or a mailbox is 400 unsupported_file. Calling it on an import that has already left uploading returns it unchanged.
Paramètres
idStringObligatoireImport id,
imp_followed by 24 hex characters.options.apiKeyStringOverrides the client's API key for this call only.
Retourne
A map for the import with status set to queued.
Exemple
Map<String, Object> queued = client.imports().start("imp_7a1c9e3b5d2f4e60a8c1d3b9"); System.out.println(queued.get("status"));Aussi disponible dans
imports().cancel
Cancel a mailbox import
Map<String, Object> cancel(String id, RequestOptions options)Stops an import at its next checkpoint. Mail already imported stays in the mailbox. A finished import is 409 not_cancellable.
Paramètres
idStringObligatoireImport id,
imp_followed by 24 hex characters.options.apiKeyStringOverrides the client's API key for this call only.
Retourne
A map for the import with status set to cancelled.
Exemple
Map<String, Object> result = client.imports().cancel("imp_3f9c2a7b1e4d8f60a5c7b92d"); System.out.println(result.get("id") + " " + result.get("status"));Aussi disponible dans
imports().listFailures
List what an import could not bring across
Map<String, Object> listFailures(String id, RequestOptions options)Each message or archive entry that did not come across, with the reason: too-large (over 50 MB), unparseable, no-date, storage-error, unreadable-entry, encrypted-entry or archive-limit. Page with after, passing the nextCursor of the previous page.
Paramètres
idStringObligatoireImport id,
imp_followed by 24 hex characters.options.afterintThe
nextCursorof the previous page.options.limitintAt most 100, the default.
options.apiKeyStringOverrides the client's API key for this call only.
Retourne
A map with data, a list of failures, and nextCursor, the number to pass as after for the next page, or null after the last one.
Exemple
Map<String, Object> page = client.imports().listFailures("imp_7a1c9e3b5d2f4e60a8c1d3b9", RequestOptions.create().limit(50)); for (Object entry : (List<?>) page.get("data")) { Map<?, ?> failure = (Map<?, ?>) entry; System.out.println(failure.get("reason") + " " + failure.get("subject"));}Aussi disponible dans
imports().deleteUpload
Delete the files uploaded for an import
Map<String, Object> deleteUpload(String id, RequestOptions options)Removes the uploaded archive. Mail already imported stays in the mailbox. An import still uploading is cancelled at the same time, and one that is queued or running is 409 still_running.
Paramètres
idStringObligatoireImport id,
imp_followed by 24 hex characters.options.apiKeyStringOverrides the client's API key for this call only.
Retourne
A map for the import with uploadDeleted set to true.
Exemple
Map<String, Object> result = client.imports().deleteUpload("imp_3f9c2a7b1e4d8f60a5c7b92d"); System.out.println(result.get("id") + " " + result.get("status"));Aussi disponible dans
imports().importFiles
Create, upload and start an import in one call
Map<String, Object> importFiles(Map<String, Object> input, RequestOptions options)Creates the import, uploads every file part by part and starts it, reporting progress through onProgress. Pass each file's data as a byte array or as a Path to the file. Parts are sliced from it, so a Path is read one part at a time and never held in memory whole.
It returns once the import is queued. Poll imports().get to follow it.
Paramètres
input.addressIdStringObligatoireThe address the mail belongs to.
input.filesList<Map<String, Object>>ObligatoireEach file as a map with
nameanddata. A file whosedatais not one of the byte sources above throws anIllegalArgumentExceptionbefore anything is sent.input.optionsMap<String, Object>keepInbox,includeSpamandincludeTrash, as forimports().create.input.onProgressBiConsumer<Long, Long>Called after each part with two integers: the bytes uploaded so far and the total.
options.apiKeyStringOverrides the client's API key for every request of this call.
Retourne
A map for the import with status set to queued.
Exemple
BiConsumer<Long, Long> onProgress = (uploaded, total) -> System.out.println(uploaded + " of " + total + " bytes uploaded");Map<String, Object> item = client.imports().importFiles(Body.of( "addressId", "addr_5d1c9e3a7b2f4e60a8c1d3b9", "files", List.of(Body.of("name", "takeout-001.zip", "data", Path.of("takeout-001.zip"))), "onProgress", onProgress)); System.out.println(item.get("id") + " is " + item.get("status"));Remarques
If a part still fails after its retries, the exception is thrown and the import is left in
uploading.imports().uploadStatethen tells you which parts to send before callingimports().start.
Aussi disponible dans
imports().discoverMailbox
Find the mail server for an address
Map<String, Object> discoverMailbox(String email, RequestOptions options)Looks up where the mailbox behind an address lives, so an import can connect to it. It tries the providers OpenEmail knows, then who receives mail for the domain, then Mozilla's public list of mail settings, then the domain's own _imaps._tcp record. Nothing is stored and no sign-in is attempted.
server is null when nothing was found: ask for the host and port and pass them to checkMailbox. signIn says what the mailbox takes. app-password and password are what checkMailbox and connectMailbox send. An Outlook.com or Microsoft 365 mailbox answers microsoft, which only the Microsoft sign-in on the Migrations page of the app can open.
Paramètres
emailStringObligatoireThe address of the old mailbox.
options.apiKeyStringOverrides the client API key for this call only.
Retourne
A map with provider, signIn, server, source, username and whether contacts and calendars can come across too.
Exemple
Map<String, Object> settings = client.imports().discoverMailbox("[email protected]"); System.out.println(settings.get("signIn") + " " + settings.get("provider") + " " + settings.get("server"));Remarques
Something that is not an email address is a 400
mailbox_address_invalid.Too many lookups in an hour is a 429
mailbox_checks_limited.A GET is retried automatically on network failure and on 408, 500, 502, 503 and 504 responses, up to the client
maxRetries, and on a 429 only when it carries aRetry-Afterof a minute or less.
Aussi disponible dans
imports().checkMailbox
Check a mailbox before importing it
Map<String, Object> checkMailbox(Map<String, Object> body, RequestOptions options)Signs in to the old mailbox over IMAP, lists its folders and counts the messages, then signs out. Nothing is stored, the password is not kept and the old mailbox is not changed. Use it to show what an import would bring before starting one.
Leave host out to have the server looked up from the address, as discoverMailbox does. Only port 993 with TLS, or port 143 with STARTTLS, is accepted. Each person may make 10 sign-in attempts an hour across checkMailbox, connectMailbox and resume, and every refused sign-in reads the same, whatever the reason.
Paramètres
body.emailStringObligatoireThe address of the old mailbox.
body.passwordStringObligatoireThe password of the old mailbox, or an app password where
discoverMailboxanswerssignInset toapp-password.body.hostStringThe IMAP host, such as
imap.example.com. It has to be a public host. Left out, the server is looked up from the address.body.portint993 or 143, read only with
host. Left out, it followssecurity: 993 fortlsand 143 forstarttls.body.securityStringtlsorstarttls, read only withhost. Left out, it followsport, and istlswhen both are left out.body.usernameStringThe name to sign in with. Left out, it is the
usernamethatdiscoverMailboxanswers, usually the address.options.apiKeyStringOverrides the client API key for this call only.
Retourne
A map with the server and username that worked, up to 200 folders with their role, messages and whether an import with the default options reads them, and the total messages an import would read.
Exemple
Map<String, Object> check = client.imports().checkMailbox(Body.of("email", "[email protected]", "password", System.getenv("OLD_MAILBOX_PASSWORD"))); System.out.println(check.get("messages") + " " + check.get("folders"));Remarques
A sign-in the mail server does not accept is a 400
mailbox_login_failed, with no more detail than that.No server found for the address is a 400
mailbox_settings_unknown: sendhost. A host that is not public, or a port other than 993 or 143, is a 400mailbox_host_not_allowed.A mailbox that only opens through the Microsoft sign-in is a 400
mailbox_uses_microsoft.A mail server that does not answer is a 502
mailbox_unreachable, and too many sign-in attempts in an hour is a 429mailbox_checks_limited.Spam and bin folders come back with
includedset tofalse, since an import reads them only when asked to.Not retried automatically.
Aussi disponible dans
imports().connectMailbox
Import a live mailbox
Map<String, Object> connectMailbox(Map<String, Object> body, RequestOptions options)Starts copying an old mailbox into one address, straight from its mail server. It signs in once to check the password, keeps the password sealed until the import finishes and for 30 days at most, and queues the import. Poll get for progress.
The old mailbox is only ever read. Folders become labels, read and starred state come across, and a message the address already holds is skipped, so running an import twice adds nothing. A Gmail mailbox is read from All Mail, with its labels. An import waits by itself when the old provider slows it down, such as Gmail's daily download limit, and carries on from the same folder afterwards: status is parked and remote.resumeAt says when. If the password stops working, status is needs-password until resume sends a new one.
contacts and calendars bring those across too where the provider offers them, which needs contacts:write and calendar:write as well. They arrive as contacts and calendar imports of their own, listed in children. rerunOf names a finished import of the same mailbox, at most 30 days old, so only mail that arrived since is fetched. One import may run into an address at a time.
Paramètres
body.addressIdStringObligatoireThe address the mail belongs to. It must be an address this workspace owns and this key may act for.
body.emailStringObligatoireThe address of the old mailbox.
body.passwordStringObligatoireThe password of the old mailbox, or an app password where
discoverMailboxanswerssignInset toapp-password.body.hostStringThe IMAP host, such as
imap.example.com. It has to be a public host. Left out, the server is looked up from the address.body.portint993 or 143, read only with
host. Left out, it followssecurity: 993 fortlsand 143 forstarttls.body.securityStringtlsorstarttls, read only withhost. Left out, it followsport, and istlswhen both are left out.body.usernameStringThe name to sign in with. Left out, it is the
usernamethatdiscoverMailboxanswers, usually the address.body.options.keepInboxbooleanDefault true: mail that was in the old inbox lands in Inbox with its unread state. False files everything under Archive.
body.options.includeSpambooleanDefault false.
body.options.includeTrashbooleanDefault false.
body.contactsbooleanTrue brings the address book across too, where the provider offers it. Needs
contacts:write.body.calendarsbooleanTrue brings the calendars across too, where the provider offers them. Needs
calendar:write.body.rerunOfStringThe id of a finished import of the same mailbox, at most 30 days old. Only mail that arrived since is fetched.
options.apiKeyStringOverrides the client API key for this call only.
Retourne
A map with status set to queued, source set to imap, the remote mailbox it reads and the children it started.
Exemple
Map<String, Object> item = client.imports().connectMailbox(Body.of( "addressId", "addr_2b7e", "email", "[email protected]", "password", System.getenv("OLD_MAILBOX_PASSWORD"), "contacts", true, "calendars", true)); System.out.println(item.get("status") + " " + item.get("remote") + " " + item.get("children"));Remarques
An address with an import already under way is 409
already_running, and an import named inrerunOfthat cannot be continued is 409rerun_not_available.An address outside the workspace is 404
address_not_found, and one the key may not act for is 403address_not_allowed.The sign-in is checked before anything is queued, so it fails as
checkMailboxdoes: 400mailbox_login_failed,mailbox_settings_unknown,mailbox_host_not_allowedormailbox_uses_microsoft, 502mailbox_unreachableand 429mailbox_checks_limited.childrenis filled here and byget.listreturns it empty.Not retried automatically.
Aussi disponible dans
imports().resume
Resume a waiting mailbox import
Map<String, Object> resume(String id, Map<String, Object> body, RequestOptions options)Carries on an import from a live mailbox that is waiting. One with status set to parked is queued again at once, without a body. One with status set to needs-password needs the new password, which is checked against the old mailbox before the import is queued. It picks up at the folder and message it stopped at.
An import that came from a Microsoft sign-in is resumed by signing in again on the Migrations page of the app.
Paramètres
idStringObligatoireImport id,
imp_followed by 24 hex characters.body.passwordStringThe new password of the old mailbox. Required when
statusisneeds-password.options.apiKeyStringOverrides the client API key for this call only.
Retourne
A map with status set to queued.
Exemple
Map<String, Object> parked = client.imports().resume("imp_3f9c2a7b1e4d8f60a5c7b92d"); System.out.println(parked.get("status"));Remarques
An import that is not waiting, or that reads uploaded files, is 409
not_resumable.Leaving
passwordout for an import that needs one is 400password_required, and a password the mail server does not accept is 400mailbox_login_failed.A new password counts towards the 10 sign-in attempts an hour that
checkMailboxandconnectMailboxshare.A parked import carries on by itself at
remote.resumeAt, so calling this only tries sooner.Not retried automatically.