.OptionalStringArray(MAILBOX_IDS_ARGUMENT,$"Optional IDs of the mailboxes to {toolAction}, out of those listed in the description of this tool. Leave it out to {toolAction} all of them.",mailboxIds)
.OptionalString(FROM_ARGUMENT,$"Optional part of the address or the name of the sender, such as 'alice@example.org', 'example.org', or 'Alice'. At most {MAX_ADDRESS_CHARACTERS} characters.")
.OptionalString(TO_ARGUMENT,$"Optional part of the address or the name of a recipient in To, Cc, or Bcc. At most {MAX_ADDRESS_CHARACTERS} characters.")
.OptionalString(AFTER_ARGUMENT,"Optional: only mails received at this point in time or later. A date such as 2026-09-01 stands for the beginning of that day in the time zone of the user. A date with a time of day such as 2026-09-01T14:30 is read in that time zone as well, unless it ends with an offset such as +02:00 or with Z.")
.OptionalString(BEFORE_ARGUMENT,"Optional: only mails received before this point in time, in the same forms as the argument after. A date stands for the beginning of that day, so before 2026-09-30 leaves that day out.")
.OptionalBoolean(IS_UNREAD_ARGUMENT,"Optional: true for unread mails only, false for read ones only.")
.OptionalBoolean(IS_FLAGGED_ARGUMENT,"Optional: true for flagged mails only, false for unflagged ones only.")
.OptionalBoolean(IS_ENCRYPTED_ARGUMENT,"Optional: true for encrypted mails only, false for unencrypted ones only. AI Studio cannot read the content of encrypted mails, only their header.")
.OptionalEnum(IMPORTANCE_ARGUMENT,"Optional importance the sender marked the mails with. Mails without such a mark count as normal.",IMPORTANCE_VALUES)
.OptionalBoolean(HAS_ATTACHMENTS_ARGUMENT,"Optional: true for mails with attachments only, false for mails without any.")
.OptionalString(FOLDER_ARGUMENT,$"Optional full path of the folder the mails lie in, exactly as results show it, such as 'INBOX' or 'Archive/2026'. Subfolders are not included. For the sent mails or the drafts, use {SPECIAL_FOLDER_ARGUMENT} instead.")
.OptionalEnum(SPECIAL_FOLDER_ARGUMENT,$"Optional: only the mails the user sent, or only the drafts of the user, however the server names these folders. Cannot be combined with {FOLDER_ARGUMENT}.",SPECIAL_FOLDER_VALUES);
varfrom=ToolArgumentReader.ReadOptionalLine(arguments,FROM_ARGUMENT,MAX_ADDRESS_CHARACTERS,"for mails from any sender");
varto=ToolArgumentReader.ReadOptionalLine(arguments,TO_ARGUMENT,MAX_ADDRESS_CHARACTERS,"for mails to any recipient");
varafter=ToolArgumentReader.ReadOptionalDateTime(arguments,AFTER_ARGUMENT,timeZone,"for mails of any age");
varbefore=ToolArgumentReader.ReadOptionalDateTime(arguments,BEFORE_ARGUMENT,timeZone,"for mails up to now");
if(afteris{}since&&beforeis{}until&&since>=until)
thrownewArgumentException(string.Create(CultureInfo.InvariantCulture,$"Argument '{AFTER_ARGUMENT}' must lie before argument '{BEFORE_ARGUMENT}', but no mail can arrive at {since:yyyy-MM-dd'T'HH:mmzzz} or later and before {until:yyyy-MM-dd'T'HH:mmzzz}. Swap the two, or leave one of them out."));
varimportance=ToolArgumentReader.ReadOptionalChoice(arguments,IMPORTANCE_ARGUMENT,IMPORTANCE_VALUES,"for mails of any importance")switch
{
null=>(MailImportance?)null,
"low"=>MailImportance.LOW,
"normal"=>MailImportance.NORMAL,
"high"=>MailImportance.HIGH,
varother=>thrownewUnreachableException($"The importance '{other}' was offered, but has no meaning."),
};
varfilter=newMailFilter
{
From=from,
To=to,
ReceivedSinceUtc=after?.ToUniversalTime(),
ReceivedBeforeUtc=before?.ToUniversalTime(),
IsUnread=ToolArgumentReader.ReadOptionalBoolean(arguments,IS_UNREAD_ARGUMENT,"for read and unread mails alike"),
IsFlagged=ToolArgumentReader.ReadOptionalBoolean(arguments,IS_FLAGGED_ARGUMENT,"for flagged and unflagged mails alike"),
IsEncrypted=ToolArgumentReader.ReadOptionalBoolean(arguments,IS_ENCRYPTED_ARGUMENT,"for encrypted and unencrypted mails alike"),
Importance=importance,
HasAttachments=ToolArgumentReader.ReadOptionalBoolean(arguments,HAS_ATTACHMENTS_ARGUMENT,"for mails with and without attachments alike"),
varother=>thrownewUnreachableException($"The special folder '{other}' was offered, but has no meaning."),
};
// Both name the one folder the mails have to lie in, and two such folders would match no mail at all:
if(folderisnotnull&&specialFolderisnotnull)
thrownewArgumentException($"Arguments '{FOLDER_ARGUMENT}' and '{SPECIAL_FOLDER_ARGUMENT}' cannot be combined, but both were given. Leave out '{FOLDER_ARGUMENT}' for the sent mails or the drafts, however the server names their folders, or leave out '{SPECIAL_FOLDER_ARGUMENT}' for the folder with the given path.");