OutlookでIMAPメールサーバを登録した時に表示されるフォルダがいまいちなことがある
その原因についていろんな調べてみた
まだアクセスしたことないけどメールが届いているユーザのメールボックス状態とそのときのディレクトリ
# doveadm mailbox list -u testuser3
INBOX
# ls -aF /var/vmail/testuser3/Maildir/
./ dovecot-uidlist dovecot.index.log tmp/
../ dovecot-uidvalidity dovecot.list.index.log
cur/ dovecot-uidvalidity.68eef53b new/
#
このときのINBOXフォルダの実態はどこかになるかを確認すると下記の様になっており、各ユーザのメールボックスのroot がINBOXとなっている、ということがわかる。
# doveadm mailbox path -u testuser3 INBOX
/var/vmail/testuser3/Maildir
#
次に、OutlookにIMAPサーバ設定を追加してログインしてみる

上記のようなメールボックスが表示される
doveadmコマンドで確認すると日本語名のメールボックスが確認できる
# doveadm mailbox list -u testuser3
迷惑メール
下書き
削除済みアイテム
送信済みアイテム
INBOX
#
実際に作られているディレクトリを確認すると、日本語文字列ではない修正UTF-7と呼ばれるものになっている。(UTF-8ベースではなくUTF-7ベースなのかは2000年以前のsendmailでは8bit目を取り扱えないシステムも存在していたため7bitで表現できる範囲に収める必要があった。これを引き継いで7bit範囲内に収まるUTF-7を採用したと思われる)
# ls -aF /var/vmail/testuser3/Maildir/
./ dovecot-uidvalidity.68eef53f
'.&Tgtm+DBN-'/ dovecot.index.cache
'.&UkqWZG4IMH8wojCkMMYw4A-'/ dovecot.index.log
'.&j,dg0TDhMPww6w-'/ dovecot.list.index.log
'.&kAFP4W4IMH8wojCkMMYw4A-'/ dovecot.mailbox.log
../ new/
cur/ subscriptions
dovecot-uidlist tmp/
dovecot-uidvalidity
#
この修正UTF-7が何を表しているかというのは、doveadmコマンドに-7,-8オプションを付与することで確認できる
# doveadm mailbox list -u testuser3 -7
&j,dg0TDhMPww6w-
&Tgtm+DBN-
&UkqWZG4IMH8wojCkMMYw4A-
&kAFP4W4IMH8wojCkMMYw4A-
INBOX
# doveadm mailbox list -u testuser3 -8
迷惑メール
下書き
削除済みアイテム
送信済みアイテム
INBOX
#
それぞれのメールボックスがどう変換されるのかを具体的に確認するのであれば、下記の様に「doveadm mailbox mutf7 -7 “文字列”」「doveadm mailbox mutf7 -8 “文字列”」と実行する
# doveadm mailbox mutf7 -7 "&j,dg0TDhMPww6w-"
迷惑メール
# doveadm mailbox mutf7 -8 "迷惑メール"
&j,dg0TDhMPww6w-
#
というわけで、Outlookで最初にIMAPメールを取りに行くと日本語でメールフォルダを作成する、ということがわかった。
Outlook形式メールボックスをThunderbirdメールで使う方法
同じユーザアカウントをThunderbirdメールで取得してみると、下記の様に表示される

じゃあ、下書き/削除済みアイテム/送信済みアイテムがOutlookと相互同期がとれているのかというと、そうはなっていなかった。
Thunderbirdの[アカウント設定]-[送信控えと特別なフォルダー]を見てみると、下記に様に、送信済みは「ローカルフォルダー」、下書きも「ローカルフォルダー」となっている。

これをどちらも各ユーザを指定する

かと思ったのですが、上記を設定しても、実際にメール送信や下書き保存してから設定を確認すると「ローカルフォルダー」に戻ります。
ただしい設定は「その他のフォルダーを指定する」を選んで、手動でフォルダを指定することでした


これで解決かと思ったのですが、「ゴミ箱」と「迷惑メール」についての設定がありません。
ゴミ箱は[サーバー設定]-[サーバー設定]にある「メッセージを削除する時」でゴミ箱を指定

迷惑メールは[迷惑メール]-[移動先と保存期間]で設定します。

で・・・ここまでの設定を行った段階でdoveadmコマンドでメールボックスを確認してみたところ、設定中にThunderbirdが「Junk」と「Trash」を別に作ってしまったようです。
# doveadm mailbox list -u testuser3
Junk
Trash
迷惑メール
下書き
削除済みアイテム
送信済みアイテム
INBOX
#
Thunderbirdメール上のメールボックス表示も「迷惑メール」が2種類、「ゴミ箱」と「削除済みアイテム」が両方ある、という状態に

Outlook側も「ゴミ箱」と「削除済みアイテム」が両方ある、という状態

これの解消についてはThunderbirdであればアカウント名の右クリックメニューから「購読」

表示される一覧の「Junk」と「Trash」のチェックを外します


下記の様に表示されます。

IMAPの購読設定はOutlook側で行うこともできます。受信トレイの右クリックメニューから「IMAPフォルダ」を選び、[クエリ]をクリックすると、下記の様にフォルダが表示されます。

「Junk」と「Trash」をそれぞれ「購読取り消し」を選んで適用します

Outlook側の表示も下記の様になります。(フォルダが残ったままの場合は一度Outlookを起動し直す)

日本語版Outlookと英語版Outlookは共存できるのか?
Outlookで自動的に作成されるのは日本語名のフォルダになっている。
じゃあ、英語環境ではどうなのか?と英語版Outlook環境を作成して、日本語版Outlook/Thunderbirdでアクセス済みのアカウントを設定してみた。

英語名のフォルダが別に作成されてしまうという事態に
# doveadm mailbox list -u testuser3
Drafts
Sent Items
Junk
Trash
迷惑メール
下書き
削除済みアイテム
送信済みアイテム
INBOX
#
英語Outlookでメール送信/下書きをすると、英語名フォルダに保存され、日本語環境のモノと同期がとれず、それぞれ別に保存されていることを確認
日本語Outlookでフォルダを確認すると下記の状態

OutlookのIMAPフォルダーでの購読状況は下記の様にどちらも共通(INBOX/受信ボックスはどちらも共通)


で・・・Thunderbirdメールの場合、とてもややこしい状態になっています

じゃあ、日本語Outlookと英語Outlookでメールボックス名を共通化することができるのか?
下書きの保存については「Change where sent email messages are saved」に記載があった
[ファイル]-[オプション]の「メール」にある「メッセージの保存」で下書きの保存場所を設定できる・・・のかと思ったら



選択できるものが、それぞれ英語/日本語でOutlookが作成したものだけとなっており、それ以外の場所が設定できないようだ。
Thunderbirdログイン後に日本語Outlookからアクセス
初回ログインはThunderbirdから行って、次に日本語Outlookからアクセスした場合の状態について確認
まずはサーバ上の初期状態を確認
# doveadm mailbox list -u testuser2
INBOX
# ls -aF testuser2/Maildir/
./ ../ cur/ dovecot.list.index.log new/ tmp/
#
Thunderbirdに設定を入れた直後は「受信トレイ」と「ゴミ箱」のみ

# doveadm mailbox list -u testuser2
Trash
INBOX
# ls -aF testuser2/Maildir/
./ dovecot-keywords dovecot.index.cache new/
../ dovecot-uidlist dovecot.index.log subscriptions
.Trash/ dovecot-uidvalidity dovecot.list.index.log tmp/
cur/ dovecot-uidvalidity.68ef30a8 dovecot.mailbox.log
#
このときのThunderbird設定を確認すると[サーバー設定]-[サーバ設定]の「メッセージを削除する時」はIMAPのフォルダーになっている

それに対して[送信控えと特別なフォルダー]は、ローカルフォルダーになっている。

これを下記の設定にしても、しばらくするとローカルフォルダ設定に戻る。

動作を確認すると、ゴミ箱については、確かにTrashフォルダにメールが移動されていることを確認できた。
この状態で、OutlookでIMAP設定を行うと下記の様になった。

# doveadm mailbox list -u testuser2
迷惑メール
下書き
送信済みアイテム
Trash
INBOX
# ls -aF testuser2/Maildir/
./ dovecot-uidvalidity
'.&Tgtm+DBN-'/ dovecot-uidvalidity.68ef30ab
'.&j,dg0TDhMPww6w-'/ dovecot.index.cache
'.&kAFP4W4IMH8wojCkMMYw4A-'/ dovecot.index.log
../ dovecot.list.index.log
.Trash/ dovecot.mailbox.log
cur/ new/
dovecot-keywords subscriptions
dovecot-uidlist tmp/
#
Thunderbirdで作成されたUI上は「ごみ箱」となっていた「Trash」フォルダは、Outlook側では「Trash」と表示され、Outlook側でメールを削除すると「Trash」フォルダにメールが移動する、ということが確認できた。
つまり、「受信トレイ」と「ゴミ箱」については、ThunderbirdとOutlookとで共通利用が可能なようだ
Outlook側で作成したフォルダが追加されたあとのThunderbird側は下記の表示となった。

このときに、Outlook側と動作を揃えるためにアカウント設定では以下の様に「その他のフォルダーを指定する」の方を選んで設定する。


下記の様にフォルダーに色がついたりする

英語版Outlookで初回ログインした場合
英語版Outlookで初回ログインした場合

# doveadm mailbox list -u testuser4
Junk Email
Drafts
Deleted Items
Sent Items
INBOX
# ls -aF testuser4/Maildir/
./ cur/ dovecot.list.index.log
../ dovecot-uidlist dovecot.mailbox.log
'.Deleted Items'/ dovecot-uidvalidity new/
.Drafts/ dovecot-uidvalidity.68ef371e subscriptions
'.Junk Email'/ dovecot.index.cache tmp/
'.Sent Items'/ dovecot.index.log
#
この状態ではThunderbirdメールから見ると以下の状態となっていた

# doveadm mailbox list -u testuser4
Trash
Junk Email
Drafts
Deleted Items
Sent Items
INBOX
#
このとき、thunderbirdの設定は下記となっており、下書きについては、自動的に「その他のフォルダー」の方で設定されている。



しかし、Thunderbirdでメールの送信と下書き保存を行ってみると送信済みは

この状態では、英語outlookとThunderbirdではゴミ箱と送信済みの同期がとれていない状態となっていた。

英語版Outlook「Deleted Items」とThunderbird「Trash」がIMAP上の別フォルダ。
英語版Outlook「Sent Items」はIMAP上だが、Thunderbirdの「送信済みトレイ/送信済みアイテム」はローカル
続いて日本語Outlookで設定をすると下記となり、この場合はフォルダ名が英語表示ではあるものの内容は英語版Outlookと同期がとれている。

dovecotの設定調整で共有化できるのか?
ここまでのところで判明した問題点
・OutlookはIMAPアクセスした時に規定のフォルダがないと新規作成する
・英語版Outlookで作ったフォルダは日本語版Outlookでも共通で使えるが、逆は別物となる
・ThunderbirdでIMAPアクセスした時は、ゴミ箱(Trash)しか作成しない
dovecotの設定で /etc/dovecot/conf.d/15-mailboxes.conf内で下記ような設定がある
namespace inbox {
# These mailboxes are widely used and could perhaps be created automatically:
mailbox Drafts {
special_use = \Drafts
}
mailbox Junk {
special_use = \Junk
}
mailbox Trash {
special_use = \Trash
}
# For \Sent mailboxes there are two widely used names. We'll mark both of
# them as \Sent. User typically deletes one of them if duplicates are created.
mailbox Sent {
special_use = \Sent
}
mailbox "Sent Messages" {
special_use = \Sent
}
special_use というのは RFC6154「IMAP LIST Extension for Special-Use Mailboxes」で定義されている特殊な役割をもつものとなっていて「\Drafts(下書き)」「\Junk(迷惑メール)」「\Trash(ゴミ箱)」「\Sent(送信済みアイテム)」の設定となっている。
すでに行われている設定をみると、「Sent」と「Sent Messages」は同じ「\Sent」を指す、という設定になっているように見える
この設定をこれまでに出てきたものに対して適用することで解決できるのでは?ということで並べると・・・
\Drafts 候補
下書き
Drafts
\Junk 候補
迷惑メール
Junk
Junk Email
\Trash 候補
削除済みアイテム
Trash
Deleted Items
\Sent 候補
送信済みアイテム
Sent Items
これを /etc/dovecot/conf.d/15-mailboxes.conf に設定してdovecot再起動
##
## Mailbox definitions
##
# Each mailbox is specified in a separate mailbox section. The section name
# specifies the mailbox name. If it has spaces, you can put the name
# "in quotes". These sections can contain the following mailbox settings:
#
# auto:
# Indicates whether the mailbox with this name is automatically created
# implicitly when it is first accessed. The user can also be automatically
# subscribed to the mailbox after creation. The following values are
# defined for this setting:
#
# no - Never created automatically.
# create - Automatically created, but no automatic subscription.
# subscribe - Automatically created and subscribed.
#
# special_use:
# A space-separated list of SPECIAL-USE flags (RFC 6154) to use for the
# mailbox. There are no validity checks, so you could specify anything
# you want in here, but it's not a good idea to use flags other than the
# standard ones specified in the RFC:
#
# \All - This (virtual) mailbox presents all messages in the
# user's message store.
# \Archive - This mailbox is used to archive messages.
# \Drafts - This mailbox is used to hold draft messages.
# \Flagged - This (virtual) mailbox presents all messages in the
# user's message store marked with the IMAP \Flagged flag.
# \Important - This (virtual) mailbox presents all messages in the
# user's message store deemed important to user.
# \Junk - This mailbox is where messages deemed to be junk mail
# are held.
# \Sent - This mailbox is used to hold copies of messages that
# have been sent.
# \Trash - This mailbox is used to hold messages that have been
# deleted.
#
# comment:
# Defines a default comment or note associated with the mailbox. This
# value is accessible through the IMAP METADATA mailbox entries
# "/shared/comment" and "/private/comment". Users with sufficient
# privileges can override the default value for entries with a custom
# value.
# NOTE: Assumes "namespace inbox" has been defined in 10-mail.conf.
namespace inbox {
# These mailboxes are widely used and could perhaps be created automatically:
mailbox Drafts {
special_use = \Drafts
}
mailbox "下書き" {
special_use = \Drafts
}
mailbox Junk {
special_use = \Junk
}
mailbox "迷惑メール" {
special_use = \Junk
}
mailbox "Junk Email" {
special_use = \Junk
}
mailbox Trash {
special_use = \Trash
}
mailbox "削除済みアイテム" {
special_use = \Trash
}
mailbox "Deleted Items" {
special_use = \Trash
}
# For \Sent mailboxes there are two widely used names. We'll mark both of
# them as \Sent. User typically deletes one of them if duplicates are created.
mailbox Sent {
special_use = \Sent
}
mailbox "Sent Messages" {
special_use = \Sent
}
mailbox "送信済みアイテム" {
special_use = \Sent
}
mailbox "Sent Items" {
special_use = \Sent
}
# If you have a virtual "All messages" mailbox:
#mailbox virtual/All {
# special_use = \All
# comment = All my messages
#}
# If you have a virtual "Flagged" mailbox:
#mailbox virtual/Flagged {
# special_use = \Flagged
# comment = All my flagged messages
#}
# If you have a virtual "Important" mailbox:
#mailbox virtual/Important {
# special_use = \Important
# comment = All my important messages
#}
}
初期状態
# doveadm mailbox list -u testuser5
INBOX
# ls -aF testuser5/Maildir/
./ ../ cur/ new/ tmp/
#
日本語Outlookで最初に作成した場合
日本語Outlookでログイン

# doveadm mailbox list -u testuser5
迷惑メール
下書き
削除済みアイテム
送信済みアイテム
INBOX
# ls -aF testuser5/Maildir/
./ dovecot-uidvalidity.68ef4b2b
'.&Tgtm+DBN-'/ dovecot.index.cache
'.&UkqWZG4IMH8wojCkMMYw4A-'/ dovecot.index.log
'.&j,dg0TDhMPww6w-'/ dovecot.list.index.log
'.&kAFP4W4IMH8wojCkMMYw4A-'/ dovecot.mailbox.log
../ new/
cur/ subscriptions
dovecot-uidlist tmp/
dovecot-uidvalidity
#
続いて英語Outlookでログインした場合

# doveadm mailbox list -u testuser5
迷惑メール
下書き
削除済みアイテム
送信済みアイテム
INBOX
# ls -aF testuser5/Maildir/
./ dovecot-uidvalidity.68ef4b2b
'.&Tgtm+DBN-'/ dovecot.index.cache
'.&UkqWZG4IMH8wojCkMMYw4A-'/ dovecot.index.log
'.&j,dg0TDhMPww6w-'/ dovecot.list.index.log
'.&kAFP4W4IMH8wojCkMMYw4A-'/ dovecot.mailbox.log
../ new/
cur/ subscriptions
dovecot-uidlist tmp/
dovecot-uidvalidity
#
英語版Outlookであっても、日本語文字列でのフォルダが見えており、ゴミ箱/下書き/送信済みアイテムの内容が日本語版Outlookと同期がとれていることを確認できた。
Thunderbirdで設定すると以下の状態で見れる

Thunderbirdの[サーバー設定]の「メールを削除するとき」の初期値は下記となっていて、ちゃんと選択されてるのか?という感じでしたが、メールを削除すると、IMAP上のTrashに移動してることを確認しました

[送信控えと特別なフォルダー]は下記


日本語版Outlook、英語版Outlook、Thunderbirdメールのそれぞれで同期がとれたように見える。
英語Outlookで最初に作成した場合
英語Outlookで最初にアクセスした場合に作成されるもの

# doveadm mailbox list -u testuser5
Junk Email
Drafts
Deleted Items
Sent Items
INBOX
# ls -aF testuser5/Maildir/
./ cur/ dovecot.list.index.log
../ dovecot-uidlist dovecot.mailbox.log
'.Deleted Items'/ dovecot-uidvalidity new/
.Drafts/ dovecot-uidvalidity.68ef4f73 subscriptions
'.Junk Email'/ dovecot.index.cache tmp/
'.Sent Items'/ dovecot.index.log
#
続いて日本語Outlookでログイン

実際に作成されているメールボックスは英語のまま
# doveadm mailbox list -u testuser5
Junk Email
Drafts
Deleted Items
Sent Items
INBOX
# ls -aF testuser5/Maildir/
./ cur/ dovecot.list.index.log
../ dovecot-uidlist dovecot.mailbox.log
'.Deleted Items'/ dovecot-uidvalidity new/
.Drafts/ dovecot-uidvalidity.68ef4f73 subscriptions
'.Junk Email'/ dovecot.index.cache tmp/
'.Sent Items'/ dovecot.index.log
#
最後にThunderbirdは下記状態で、特に問題は無い状態となっていた。

日本語Outlookで作成された「削除済みアイテム」の選択表示がおかしかったが、英語文字列の場合は特に問題ないようだ。



Thunderbirdで最初にアクセスした場合
Thuderbirdで最初にアクセスした場合は下記の様になった

# doveadm mailbox list -u testuser5
Trash
INBOX
# ls -aF testuser5/Maildir/
./ dovecot-keywords dovecot.index.cache new/
../ dovecot-uidlist dovecot.index.log subscriptions
.Trash/ dovecot-uidvalidity dovecot.list.index.log tmp/
cur/ dovecot-uidvalidity.68ef52a1 dovecot.mailbox.log
#
このとき、設定は、ゴミ箱はIMAP上を使用するが、「送信済みアイテム」と「下書き」についてはローカルに保存する設定になっていた。



この状態で、日本語Outlookからアクセスすると、日本語名で作成される

# doveadm mailbox list -u testuser5
迷惑メール
下書き
送信済みアイテム
Trash
# ls -aF testuser5/Maildir/
./ dovecot-uidvalidity
'.&Tgtm+DBN-'/ dovecot-uidvalidity.68ef52a4
'.&j,dg0TDhMPww6w-'/ dovecot.index.cache
'.&kAFP4W4IMH8wojCkMMYw4A-'/ dovecot.index.log
../ dovecot.list.index.log
.Trash/ dovecot.mailbox.log
cur/ new/
dovecot-keywords subscriptions
dovecot-uidlist tmp/
#
改めてthunderbird側で確認すると、下記の状態に変更されているが下書きと送信済みアイテムの同期が出来ていない

設定を確認すると、アイコンの絵がそれっぽく表示されているだけで、設定自体は手動で変更する必要があった。


これを下記に変更したところ同期が行われるようになった

設定追加
RFC6154を読むと、special useとして定義さえている文字列には「\Archive」「\Flagged」とゴミ箱/迷惑メールを含めて全メールを表示する「\All」がある模様
「\Archive」は、Outlookの各メールの右クリックメニューにある「Archive/アーカイブ」で保存される先として使用される。

# doveadm mailbox list -u testuser4
Archive
Junk
Trash
Junk Email
Drafts
Deleted Items
Sent Items
INBOX
# ls -aF testuser4/Maildir/
./ .Trash/ dovecot.list.index
../ cur/ dovecot.list.index.log
.Archive/ dovecot-keywords dovecot.list.index.log.2
'.Deleted Items'/ dovecot-uidlist dovecot.mailbox.log
.Drafts/ dovecot-uidvalidity new/
.Junk/ dovecot-uidvalidity.68ef3721 subscriptions
'.Junk Email'/ dovecot.index.cache tmp/
'.Sent Items'/ dovecot.index.log
#
上記のように「Archive」フォルダが作成される。このフォルダについては日本語Outlook環境でも英語表記Archiveでアーカイブ動作をした。
次に、最初に日本語Outlook環境で「アーカイブ」した場合は、日本語で作成される
# doveadm mailbox list -u testuser5
アーカイブ
迷惑メール
下書き
送信済みアイテム
Trash
INBOX
#
英語Outlookでアーカイブを行おうとすると、日本語アーカイブフォルダは認めてくれていない

/etc/dovecot/conf.d/15-mailboxes.confに下記設定を追加してdovecot再起動
mailbox Archive {
special_use = \Archive
}
mailbox "アーカイブ" {
special_use = \Archive
}
これで問題無くなるかと思ったのですが、引き続き”Archive”を新規作成するダイアログが表示される状態に・・・
アーカイブの動作が謎だ・・・