サイドバーの mutt ギリシャ語文字 (Offlineimap で取得したメールボックス名)

サイドバーの mutt ギリシャ語文字 (Offlineimap で取得したメールボックス名)

愚か~のサイドバー、ギリシャ文字(ギリシャ文字で指定されたメールボックス)は正しく読み取れません。とにかく両方の内部にはそのような問題はありません。インデックスとポケットベル、ギリシャ語の文字/単語/名前がよく表示されます。

                        ここに画像の説明を入力してください。

Gilesがコメントした後に更新されました。

問題の設定は、IMAPサーバーからの電子メールの読み取り/書き込みを含む2つの異なるシステム(FuntooおよびGNU bash、バージョン4.2.45(1)リリースを実行するワークステーションとラップトップ)に関するものです。 Enter email mutt。応答は次localeのとおりです。

LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE=POSIX
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

また、muttの設定ファイルにはロケール変数が設定されていません。

メッセージは実際には次のように同期されます。オフラインマップ以下を使用して送信します。サフィックスオフラインマップ、muttの構成ファイルの1つから派生したファイル(つまり名前付きファイル)にメールボックス(名前)のリストを記録しますmailboxes(表示されますsource ~/.mutt/mailboxes)。ファイルの内容を見てみると、mailboxesギリシャ名が「誤解」されたことが明らかになった。

それにもかかわらず、ギリシャ名は、同じIMAPサーバーと疑わしいメールボックスにアクセスしたWebメールクライアント(RoundCube)を介して正常にマークされています。

質問

  • なぜこれが起こるのですか?
  • offlineimap設定エラーですか?
  • どうやって解決しますか?

残りの質問は?[2015年3月](下記の回答も参照)

ただし、ローカルストレージフォルダ名(ディレクトリ名)は読み取れないままです。つまり、上記のギリシャ語のフォルダ名(Yποτροψα)は実際にはディレクトリです&A6UDwAO,A8QDwQO,A8YDrwOx-これは、同期中にではなく、フォルダ名とメッセージが同期された後にフォルダ名変換が発生することを意味しますか? または、このディレクトリを削除する必要がありますか?(ローカルリポジトリから)Offlineimapを介して別の同期を強制します。(該当するメールボックスフォルダがリモートリポジトリから削除されないように注意してください)

ベストアンサー1

要するに

「問題」は、次の事実で発生します。IMAP4は変更されたUTF-7エンコーディングを使用してフォルダ名をエンコードします。オフラインマップローカルストアが作成される前に、フォルダ名は読み取り可能な名前(UTF-8形式など)に変換されません。これにより、この質問のスクリーンショットに示すように、読み取れないフォルダ名が派生します。したがって、両方ではありません。愚か...でもないオフラインマップ不適切な取り扱いまたは誤った構成自体。

次のブログ投稿とgitリポジトリは、この問題を詳しく説明し解決します。

解決策

本質的に、Pythonスクリプト(下記)は、オフラインimapの設定ファイルに入力できるように、人間が読めるフォルダ名をエクスポートするのに役立ちますofflineimaprcオフラインIMAPマニュアル)。また、正しいフォルダ名変換(pythonスクリプトで定義された関数を使用)のための有益なコード行もあります。

# Name translation from UTF7 to UTF8
nametrans = lambda foldername: foldername.decode('imap4-utf-7').encode('utf-8')

リモートストレージオプションセクションの下のオフラインimap設定ファイルに追加されました。

アップデート(2015年4月)

もう一つのルールは必須逆動作参照フォルダのフィルタリングと名前の翻訳。手順は次のとおりです。

# Name translation, reverse!
nametrans = lambda foldername: foldername.decode('utf-8').encode('imap4-utf-7')

このmailboxesファイルには、オフラインimapで生成されたギリシャ語の名前が正しく表示されます。これにより、mutt内の問題が解決され、フォルダ名が期待どおりに表示されます(この場合はギリシャ名)。ここに画像の説明を入力してください。


残りの質問は?

ただし、ローカルストレージフォルダ名(ディレクトリ名)は読み取れないままです。つまり、上記のギリシャ語のフォルダ名(Yποτροψα)は実際にはディレクトリです&A6UDwAO,A8QDwQO,A8YDrwOx-これは、同期中ではなく、フォルダ名とメッセージが同期された後にフォルダ名変換が発生することを意味しますか? または、このディレクトリを削除する必要がありますか?(ローカルリポジトリから)Offlineimapを介して別の同期を強制します。(該当するメールボックスフォルダがリモートリポジトリから削除されないように注意してください)


国際電子メール名(IMAP、UTF-7)を処理するPythonスクリプト:

# vim:fileencoding=utf-8

r"""
Imap folder names are encoded using a special version of utf-7 as defined in RFC
2060 section 5.1.3.

From: http://piao-tech.blogspot.com/2010/03/get-offlineimap-working-with-non-ascii.html

5.1.3.  Mailbox International Naming Convention

   By convention, international mailbox names are specified using a
   modified version of the UTF-7 encoding described in [UTF-7].  The
   purpose of these modifications is to correct the following problems
   with UTF-7:

    1) UTF-7 uses the "+" character for shifting; this conflicts with
     the common use of "+" in mailbox names, in particular USENET
     newsgroup names.

    2) UTF-7's encoding is BASE64 which uses the "/" character; this
     conflicts with the use of "/" as a popular hierarchy delimiter.

    3) UTF-7 prohibits the unencoded usage of "\"; this conflicts with
     the use of "\" as a popular hierarchy delimiter.

    4) UTF-7 prohibits the unencoded usage of "~"; this conflicts with
     the use of "~" in some servers as a home directory indicator.

    5) UTF-7 permits multiple alternate forms to represent the same
     string; in particular, printable US-ASCII chararacters can be
     represented in encoded form.

   In modified UTF-7, printable US-ASCII characters except for "&"
   represent themselves; that is, characters with octet values 0x20-0x25
   and 0x27-0x7e.  The character "&" (0x26) is represented by the two-
   octet sequence "&-".

   All other characters (octet values 0x00-0x1f, 0x7f-0xff, and all
   Unicode 16-bit octets) are represented in modified BASE64, with a
   further modification from [UTF-7] that "," is used instead of "/".
   Modified BASE64 MUST NOT be used to represent any printing US-ASCII
   character which can represent itself.

   "&" is used to shift to modified BASE64 and "-" to shift back to US-
   ASCII.  All names start in US-ASCII, and MUST end in US-ASCII (that
   is, a name that ends with a Unicode 16-bit octet MUST end with a "-
   ").

    For example, here is a mailbox name which mixes English, Japanese,
    and Chinese text: ~peter/mail/&ZeVnLIqe-/&U,BTFw-

"""

import binascii
import codecs

# encoding
def modified_base64(s):
  s = s.encode('utf-16be')
  return binascii.b2a_base64(s).rstrip(b'\n=').replace(b'/', b',').decode('ascii')

def doB64(_in, r):
  if _in:
    r.append('&%s-' % modified_base64(''.join(_in)))
    del _in[:]

def encoder(s):
  r = []
  _in = []
  for c in s:
    ordC = ord(c)
    if 0x20 <= ordC <= 0x25 or 0x27 <= ordC <= 0x7e:
      doB64(_in, r)
      r.append(c)
    elif c == '&':
      doB64(_in, r)
      r.append('&-')
    else:
      _in.append(c)
  doB64(_in, r)
  return (''.join(r).encode('ascii'), len(s))

# decoding
def modified_unbase64(s):
  b = binascii.a2b_base64(s.replace(b',', b'/') + b'===')
  return str(b, 'utf-16be')

def decoder(s):
  r = []
  decode = []
  for c in s:
    if c == b'&' and not decode:
      decode.append(b'&')
    elif c == b'-' and decode:
      if len(decode) == 1:
        r.append('&')
      else:
        r.append(modified_unbase64(b''.join(decode[1:])))
      decode = []
    elif decode:
      decode.append(c)
    else:
      r.append(c.decode('ascii'))
  if decode:
    r.append(modified_unbase64(b''.join(decode[1:])))
  bin_str = ''.join(r)
  return (bin_str, len(s))

class StreamReader(codecs.StreamReader):
  def decode(self, s, errors='strict'):
    return decoder(s)

class StreamWriter(codecs.StreamWriter):
  def decode(self, s, errors='strict'):
    return encoder(s)

def imap4_utf_7(name):
  if name == 'imap4-utf-7':
    return (encoder, decoder, StreamReader, StreamWriter)

codecs.register(imap4_utf_7)

おすすめ記事