We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
mail: namecollision in dict with mailbox named 'mail'
If you have a mailbox with 
```
'name' = 'mail'
```
the unread mails in this mailbox are counted twice and will reset the count for the mailboxes that have come before it. This is caused by line [208](https://github.com/ultrabug/py3status/blob/109e60a360db6deebe719a67afa07ade4e03640a/py3status/modules/mail.py#L208) as `mail_data['mail']` is set to count_mail and at Line [213](https://github.com/ultrabug/py3status/blob/109e60a360db6deebe719a67afa07ade4e03640a/py3status/modules/mail.py#L213)
 it is added again.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `py3status/modules/mail.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 """
3 Display number of messages in various mailbox formats.
4 This module supports Maildir, mbox, MH, Babyl, MMDF, and IMAP.
5 
6 Configuration parameters:
7     accounts: specify a dict consisting of mailbox types and a list of dicts
8         consisting of mailbox settings and/or paths to use (default {})
9     cache_timeout: refresh interval for this module (default 60)
10     format: display format for this module
11         (default '\?not_zero Mail {mail}|No Mail')
12     thresholds: specify color thresholds to use (default [])
13 
14 Format placeholders:
15     {mail}    number of messages
16     {maildir} number of Maildir messages
17     {mbox}    number of mbox messages
18     {mh}      number of MH messages
19     {babyl}   number of Babyl messages
20     {mmdf}    number of MMDF messages
21     {imap}    number of IMAP messages
22 
23     We can divide mailbox, eg `{maildir}`, into numbered placeholders based
24     on number of mailbox accounts, eg `{maildir_1}`, and if we add `name` to
25     a mailbox account, we can use `{name}` placeholder instead, eg `{home}`.
26 
27 Color thresholds:
28     xxx: print a color based on the value of `xxx` placeholder
29 
30 Examples:
31 ```
32 # add multiple accounts
33 mail {                                       #
34     accounts = {                             #     {mail}
35         'maildir': [                         #      ├── {maildir}
36             {'path': '~/.mutt'},             #      │    ├── {maildir_1}
37             {'path': '~/Mail'},              #      │    └── {maildir_2}
38         ],                                   #      │
39         'mbox': [                            #      ├── {mbox}
40             {'path': '~/home.mbox'},         #      │    ├── {mbox_1}
41             {                                #      │    ├── {mbox_2}
42                 'name': 'local',             # <----│----│----└── {local}
43                 'path': '~/mbox'             #      │    │
44             },                               #      │    │
45             {                                #      │    └── {mbox_3}
46                 'name': 'debian',            # <----│---------└── {debian}
47                 'path': '/var/mail/$USER'    #      │
48                 'urgent': False,             # <----│---- disable urgent
49             },                               #      │
50         ],                                   #      │
51         'mh': [                              #      ├── {mh}
52             {'path': '~/mh_mail'},           #      │    └── {mh_1}
53         ],                                   #      │
54         'babyl': [                           #      ├── {babyl}
55             {'path': '~/babyl_mail'},        #      │    └── {babyl_1}
56         ],                                   #      │
57         'mmdf': [                            #      ├── {mmdf}
58             {'path': '~/mmdf_mail'},         #      │    └── {mmdf_1}
59         ]                                    #      │
60         'imap': [                            #      ├── {imap}
61             {                                #      │    ├── {imap_1}
62                 'name': 'home',              # <----│----│----└── {home}
63                 'user': 'lasers',            #      │    │
64                 'password': 'kiss_my_butt!', #      │    │
65                 'server': 'imap.gmail.com',  #      │    │ 
66                 'port': 993,                 #      │    │
67             },                               #      │    │
68             {                                #      │    └── {imap_2}
69                 'name': 'work',              # <----│---------└── {work}
70                 'user': 'tobes',             #      │
71                 'password': 'i_love_python', #
72                 'server': 'imap.yahoo.com',  #
73                                              # <---- no port, use port 993
74                 'urgent': False,             # <---- disable urgent
75             }                                #
76         ]
77     }
78     allow_urgent = False             <---- disable urgent for all accounts
79 }
80 
81 # add colors, disable urgent
82 mail {
83     format = '[\?color=mail&show Mail] {mail}'
84     thresholds = [(1, 'good'), (5, 'degraded'), (15, 'bad')]
85     allow_urgent = False
86 }
87 
88 # identify the mailboxes, remove what you don't need
89 mail {
90     format = '[\?color=mail '
91     format += '[\?if=imap&color=#00ff00 IMAP ]'
92     format += '[\?if=maildir&color=#ffff00 MAILDIR ]'
93     format += '[\?if=mbox&color=#ff0000 MBOX ]'
94     format += '[\?if=babyl&color=#ffa500 BABYL ]'
95     format += '[\?if=mmdf&color=#00bfff MMDF ]'
96     format += '[\?if=mh&color=#ee82ee MH ]'
97     format += ']'
98     format += '[\?not_zero&color Mail {mail}|No Mail]'
99 }
100 
101 # individual colorized mailboxes, remove what you don't need
102 mail {
103     format = '[\?if=imap&color=#00ff00 IMAP] {imap} '
104     format += '[\?if=maildir&color=#ffff00 MAILDIR] {maildir} '
105     format += '[\?if=mbox&color=#ff0000 MBOX] {mbox} '
106     format += '[\?if=babyl&color=#ffa500 BABYL] {babyl} '
107     format += '[\?if=mmdf&color=#00bfff MMDF] {mmdf} '
108     format += '[\?if=mh&color=#ee82ee MH] {mh}'
109     allow_urgent = False
110 }
111 ```
112 
113 @author lasers
114 
115 SAMPLE OUTPUT
116 {'full_text': 'Mail 15', 'urgent': True}
117 
118 identified
119 [
120     {'full_text': 'IMAP ', 'color': '#00ff00'},
121     {'full_text': 'MAILDIR ', 'color': '#ffff00'},
122     {'full_text': 'MBOX ', 'color': '#ff0000'},
123     {'full_text': 'Mail 15'},
124 ]
125 
126 individualized
127 [
128     {'full_text': 'IMAP ', 'color': '#00ff00'}, {'full_text': 'Mail 10 '},
129     {'full_text': 'MAILDIR ', 'color': '#ffff00'}, {'full_text': 'Mail 2 '},
130     {'full_text': 'MBOX ', 'color': '#ff0000'}, {'full_text': 'Mail 3'},
131 ]
132 
133 no_mail
134 {'full_text': 'No Mail'}
135 """
136 
137 import mailbox
138 from imaplib import IMAP4_SSL
139 from os.path import exists, expanduser, expandvars
140 STRING_MISSING = 'missing {} {}'
141 
142 
143 class Py3status:
144     """
145     """
146     # available configuration parameters
147     accounts = {}
148     cache_timeout = 60
149     format = '\?not_zero Mail {mail}|No Mail'
150     thresholds = []
151 
152     def post_config_hook(self):
153         if not self.accounts:
154             raise Exception('missing accounts')
155 
156         self.mailboxes = {}
157         mailboxes = ['Maildir', 'mbox', 'mh', 'Babyl', 'MMDF', 'IMAP']
158         for mail, accounts in self.accounts.items():
159             if mail not in [x.lower() for x in mailboxes]:
160                 continue
161             self.mailboxes[mail] = []
162             for account in accounts:
163                 account.setdefault('urgent', True)
164                 if mail == 'imap':
165                     for v in ['user', 'password', 'server']:
166                         if v not in account:
167                             raise Exception(STRING_MISSING.format(mail, v))
168                     account.setdefault('port', 993)
169                     self.mailboxes[mail].append(account)
170                 else:
171                     for box in mailboxes[:-1]:
172                         if mail == box.lower():
173                             if 'path' not in account:
174                                 raise Exception(
175                                     STRING_MISSING.format(mail, 'path')
176                                 )
177                             path = expandvars(expanduser(account['path']))
178                             if not exists(path):
179                                 path = 'path: {}'.format(path)
180                                 raise Exception(
181                                     STRING_MISSING.format(mail, path)
182                                 )
183                             account['box'] = box
184                             account['path'] = path
185                             self.mailboxes[mail].append(account)
186                             break
187 
188         self.thresholds_init = self.py3.get_color_names_list(self.format)
189 
190     def mail(self):
191         mail_data = {'mail': 0, 'urgent': False}
192         for k, v in self.mailboxes.items():
193             mail_data[k] = 0
194             for i, account in enumerate(v, 1):
195                 if k == 'imap':
196                     inbox = IMAP4_SSL(account['server'], account['port'])
197                     inbox.login(account['user'], account['password'])
198                     inbox.select(readonly=True)
199                     imap_data = inbox.search(None, '(UNSEEN)')
200                     count_mail = len(imap_data[1][0].split())
201                     inbox.close()
202                     inbox.logout()
203                 else:
204                     inbox = getattr(mailbox, account['box'])(
205                         account['path'], create=False)
206                     count_mail = len(inbox)
207                     inbox.close()
208                 if 'name' in account:
209                     mail_data[account['name']] = count_mail
210                 if account['urgent'] and count_mail:
211                     mail_data['urgent'] = True
212                 mail_data['%s_%s' % (k, i)] = count_mail
213                 mail_data['mail'] += count_mail
214                 mail_data[k] += count_mail
215 
216         for x in self.thresholds_init:
217             if x in mail_data:
218                 self.py3.threshold_get_color(mail_data[x], x)
219 
220         response = {
221             'cached_until': self.py3.time_in(self.cache_timeout),
222             'full_text': self.py3.safe_format(self.format, mail_data)
223         }
224         if mail_data['urgent']:
225             response['urgent'] = True
226         return response
227 
228 
229 if __name__ == "__main__":
230     """
231     Run module in test mode.
232     """
233     from py3status.module_test import module_test
234     module_test(Py3status)
235
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/py3status/modules/mail.py b/py3status/modules/mail.py
--- a/py3status/modules/mail.py
+++ b/py3status/modules/mail.py
@@ -138,6 +138,8 @@
 from imaplib import IMAP4_SSL
 from os.path import exists, expanduser, expandvars
 STRING_MISSING = 'missing {} {}'
+STRING_WRONG_NAME = 'Accountname ({}) collides with "Maildir", "mbox", "mh", \
+"Babyl", "MMDF", "mail" or "IMAP".'
 
 
 class Py3status:
@@ -160,6 +162,9 @@
                 continue
             self.mailboxes[mail] = []
             for account in accounts:
+                if account['name'] in [x.lower() for x in mailboxes] \
+                        + ['mail']:
+                    raise Exception(STRING_WRONG_NAME.format(account['name']))
                 account.setdefault('urgent', True)
                 if mail == 'imap':
                     for v in ['user', 'password', 'server']:

{"golden_diff": "diff --git a/py3status/modules/mail.py b/py3status/modules/mail.py\n--- a/py3status/modules/mail.py\n+++ b/py3status/modules/mail.py\n@@ -138,6 +138,8 @@\n from imaplib import IMAP4_SSL\n from os.path import exists, expanduser, expandvars\n STRING_MISSING = 'missing {} {}'\n+STRING_WRONG_NAME = 'Accountname ({}) collides with \"Maildir\", \"mbox\", \"mh\", \\\n+\"Babyl\", \"MMDF\", \"mail\" or \"IMAP\".'\n \n \n class Py3status:\n@@ -160,6 +162,9 @@\n                 continue\n             self.mailboxes[mail] = []\n             for account in accounts:\n+                if account['name'] in [x.lower() for x in mailboxes] \\\n+                        + ['mail']:\n+                    raise Exception(STRING_WRONG_NAME.format(account['name']))\n                 account.setdefault('urgent', True)\n                 if mail == 'imap':\n                     for v in ['user', 'password', 'server']:\n", "issue": "mail: namecollision in dict with mailbox named 'mail'\nIf you have a mailbox with \r\n```\r\n'name' = 'mail'\r\n```\r\nthe unread mails in this mailbox are counted twice and will reset the count for the mailboxes that have come before it. This is caused by line [208](https://github.com/ultrabug/py3status/blob/109e60a360db6deebe719a67afa07ade4e03640a/py3status/modules/mail.py#L208) as `mail_data['mail']` is set to count_mail and at Line [213](https://github.com/ultrabug/py3status/blob/109e60a360db6deebe719a67afa07ade4e03640a/py3status/modules/mail.py#L213)\r\n it is added again.\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"\nDisplay number of messages in various mailbox formats.\nThis module supports Maildir, mbox, MH, Babyl, MMDF, and IMAP.\n\nConfiguration parameters:\n    accounts: specify a dict consisting of mailbox types and a list of dicts\n        consisting of mailbox settings and/or paths to use (default {})\n    cache_timeout: refresh interval for this module (default 60)\n    format: display format for this module\n        (default '\\?not_zero Mail {mail}|No Mail')\n    thresholds: specify color thresholds to use (default [])\n\nFormat placeholders:\n    {mail}    number of messages\n    {maildir} number of Maildir messages\n    {mbox}    number of mbox messages\n    {mh}      number of MH messages\n    {babyl}   number of Babyl messages\n    {mmdf}    number of MMDF messages\n    {imap}    number of IMAP messages\n\n    We can divide mailbox, eg `{maildir}`, into numbered placeholders based\n    on number of mailbox accounts, eg `{maildir_1}`, and if we add `name` to\n    a mailbox account, we can use `{name}` placeholder instead, eg `{home}`.\n\nColor thresholds:\n    xxx: print a color based on the value of `xxx` placeholder\n\nExamples:\n```\n# add multiple accounts\nmail {                                       #\n    accounts = {                             #     {mail}\n        'maildir': [                         #      \u251c\u2500\u2500 {maildir}\n            {'path': '~/.mutt'},             #      \u2502    \u251c\u2500\u2500 {maildir_1}\n            {'path': '~/Mail'},              #      \u2502    \u2514\u2500\u2500 {maildir_2}\n        ],                                   #      \u2502\n        'mbox': [                            #      \u251c\u2500\u2500 {mbox}\n            {'path': '~/home.mbox'},         #      \u2502    \u251c\u2500\u2500 {mbox_1}\n            {                                #      \u2502    \u251c\u2500\u2500 {mbox_2}\n                'name': 'local',             # <----\u2502----\u2502----\u2514\u2500\u2500 {local}\n                'path': '~/mbox'             #      \u2502    \u2502\n            },                               #      \u2502    \u2502\n            {                                #      \u2502    \u2514\u2500\u2500 {mbox_3}\n                'name': 'debian',            # <----\u2502---------\u2514\u2500\u2500 {debian}\n                'path': '/var/mail/$USER'    #      \u2502\n                'urgent': False,             # <----\u2502---- disable urgent\n            },                               #      \u2502\n        ],                                   #      \u2502\n        'mh': [                              #      \u251c\u2500\u2500 {mh}\n            {'path': '~/mh_mail'},           #      \u2502    \u2514\u2500\u2500 {mh_1}\n        ],                                   #      \u2502\n        'babyl': [                           #      \u251c\u2500\u2500 {babyl}\n            {'path': '~/babyl_mail'},        #      \u2502    \u2514\u2500\u2500 {babyl_1}\n        ],                                   #      \u2502\n        'mmdf': [                            #      \u251c\u2500\u2500 {mmdf}\n            {'path': '~/mmdf_mail'},         #      \u2502    \u2514\u2500\u2500 {mmdf_1}\n        ]                                    #      \u2502\n        'imap': [                            #      \u251c\u2500\u2500 {imap}\n            {                                #      \u2502    \u251c\u2500\u2500 {imap_1}\n                'name': 'home',              # <----\u2502----\u2502----\u2514\u2500\u2500 {home}\n                'user': 'lasers',            #      \u2502    \u2502\n                'password': 'kiss_my_butt!', #      \u2502    \u2502\n                'server': 'imap.gmail.com',  #      \u2502    \u2502\u00a0\n                'port': 993,                 #      \u2502    \u2502\n            },                               #      \u2502    \u2502\n            {                                #      \u2502    \u2514\u2500\u2500 {imap_2}\n                'name': 'work',              # <----\u2502---------\u2514\u2500\u2500 {work}\n                'user': 'tobes',             #      \u2502\n                'password': 'i_love_python', #\n                'server': 'imap.yahoo.com',  #\n                                             # <---- no port, use port 993\n                'urgent': False,             # <---- disable urgent\n            }                                #\n        ]\n    }\n    allow_urgent = False             <---- disable urgent for all accounts\n}\n\n# add colors, disable urgent\nmail {\n    format = '[\\?color=mail&show Mail] {mail}'\n    thresholds = [(1, 'good'), (5, 'degraded'), (15, 'bad')]\n    allow_urgent = False\n}\n\n# identify the mailboxes, remove what you don't need\nmail {\n    format = '[\\?color=mail '\n    format += '[\\?if=imap&color=#00ff00 IMAP ]'\n    format += '[\\?if=maildir&color=#ffff00 MAILDIR ]'\n    format += '[\\?if=mbox&color=#ff0000 MBOX ]'\n    format += '[\\?if=babyl&color=#ffa500 BABYL ]'\n    format += '[\\?if=mmdf&color=#00bfff MMDF ]'\n    format += '[\\?if=mh&color=#ee82ee MH ]'\n    format += ']'\n    format += '[\\?not_zero&color Mail {mail}|No Mail]'\n}\n\n# individual colorized mailboxes, remove what you don't need\nmail {\n    format = '[\\?if=imap&color=#00ff00 IMAP] {imap} '\n    format += '[\\?if=maildir&color=#ffff00 MAILDIR] {maildir} '\n    format += '[\\?if=mbox&color=#ff0000 MBOX] {mbox} '\n    format += '[\\?if=babyl&color=#ffa500 BABYL] {babyl} '\n    format += '[\\?if=mmdf&color=#00bfff MMDF] {mmdf} '\n    format += '[\\?if=mh&color=#ee82ee MH] {mh}'\n    allow_urgent = False\n}\n```\n\n@author lasers\n\nSAMPLE OUTPUT\n{'full_text': 'Mail 15', 'urgent': True}\n\nidentified\n[\n    {'full_text': 'IMAP ', 'color': '#00ff00'},\n    {'full_text': 'MAILDIR ', 'color': '#ffff00'},\n    {'full_text': 'MBOX ', 'color': '#ff0000'},\n    {'full_text': 'Mail 15'},\n]\n\nindividualized\n[\n    {'full_text': 'IMAP ', 'color': '#00ff00'}, {'full_text': 'Mail 10 '},\n    {'full_text': 'MAILDIR ', 'color': '#ffff00'}, {'full_text': 'Mail 2 '},\n    {'full_text': 'MBOX ', 'color': '#ff0000'}, {'full_text': 'Mail 3'},\n]\n\nno_mail\n{'full_text': 'No Mail'}\n\"\"\"\n\nimport mailbox\nfrom imaplib import IMAP4_SSL\nfrom os.path import exists, expanduser, expandvars\nSTRING_MISSING = 'missing {} {}'\n\n\nclass Py3status:\n    \"\"\"\n    \"\"\"\n    # available configuration parameters\n    accounts = {}\n    cache_timeout = 60\n    format = '\\?not_zero Mail {mail}|No Mail'\n    thresholds = []\n\n    def post_config_hook(self):\n        if not self.accounts:\n            raise Exception('missing accounts')\n\n        self.mailboxes = {}\n        mailboxes = ['Maildir', 'mbox', 'mh', 'Babyl', 'MMDF', 'IMAP']\n        for mail, accounts in self.accounts.items():\n            if mail not in [x.lower() for x in mailboxes]:\n                continue\n            self.mailboxes[mail] = []\n            for account in accounts:\n                account.setdefault('urgent', True)\n                if mail == 'imap':\n                    for v in ['user', 'password', 'server']:\n                        if v not in account:\n                            raise Exception(STRING_MISSING.format(mail, v))\n                    account.setdefault('port', 993)\n                    self.mailboxes[mail].append(account)\n                else:\n                    for box in mailboxes[:-1]:\n                        if mail == box.lower():\n                            if 'path' not in account:\n                                raise Exception(\n                                    STRING_MISSING.format(mail, 'path')\n                                )\n                            path = expandvars(expanduser(account['path']))\n                            if not exists(path):\n                                path = 'path: {}'.format(path)\n                                raise Exception(\n                                    STRING_MISSING.format(mail, path)\n                                )\n                            account['box'] = box\n                            account['path'] = path\n                            self.mailboxes[mail].append(account)\n                            break\n\n        self.thresholds_init = self.py3.get_color_names_list(self.format)\n\n    def mail(self):\n        mail_data = {'mail': 0, 'urgent': False}\n        for k, v in self.mailboxes.items():\n            mail_data[k] = 0\n            for i, account in enumerate(v, 1):\n                if k == 'imap':\n                    inbox = IMAP4_SSL(account['server'], account['port'])\n                    inbox.login(account['user'], account['password'])\n                    inbox.select(readonly=True)\n                    imap_data = inbox.search(None, '(UNSEEN)')\n                    count_mail = len(imap_data[1][0].split())\n                    inbox.close()\n                    inbox.logout()\n                else:\n                    inbox = getattr(mailbox, account['box'])(\n                        account['path'], create=False)\n                    count_mail = len(inbox)\n                    inbox.close()\n                if 'name' in account:\n                    mail_data[account['name']] = count_mail\n                if account['urgent'] and count_mail:\n                    mail_data['urgent'] = True\n                mail_data['%s_%s' % (k, i)] = count_mail\n                mail_data['mail'] += count_mail\n                mail_data[k] += count_mail\n\n        for x in self.thresholds_init:\n            if x in mail_data:\n                self.py3.threshold_get_color(mail_data[x], x)\n\n        response = {\n            'cached_until': self.py3.time_in(self.cache_timeout),\n            'full_text': self.py3.safe_format(self.format, mail_data)\n        }\n        if mail_data['urgent']:\n            response['urgent'] = True\n        return response\n\n\nif __name__ == \"__main__\":\n    \"\"\"\n    Run module in test mode.\n    \"\"\"\n    from py3status.module_test import module_test\n    module_test(Py3status)\n", "path": "py3status/modules/mail.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"\nDisplay number of messages in various mailbox formats.\nThis module supports Maildir, mbox, MH, Babyl, MMDF, and IMAP.\n\nConfiguration parameters:\n    accounts: specify a dict consisting of mailbox types and a list of dicts\n        consisting of mailbox settings and/or paths to use (default {})\n    cache_timeout: refresh interval for this module (default 60)\n    format: display format for this module\n        (default '\\?not_zero Mail {mail}|No Mail')\n    thresholds: specify color thresholds to use (default [])\n\nFormat placeholders:\n    {mail}    number of messages\n    {maildir} number of Maildir messages\n    {mbox}    number of mbox messages\n    {mh}      number of MH messages\n    {babyl}   number of Babyl messages\n    {mmdf}    number of MMDF messages\n    {imap}    number of IMAP messages\n\n    We can divide mailbox, eg `{maildir}`, into numbered placeholders based\n    on number of mailbox accounts, eg `{maildir_1}`, and if we add `name` to\n    a mailbox account, we can use `{name}` placeholder instead, eg `{home}`.\n\nColor thresholds:\n    xxx: print a color based on the value of `xxx` placeholder\n\nExamples:\n```\n# add multiple accounts\nmail {                                       #\n    accounts = {                             #     {mail}\n        'maildir': [                         #      \u251c\u2500\u2500 {maildir}\n            {'path': '~/.mutt'},             #      \u2502    \u251c\u2500\u2500 {maildir_1}\n            {'path': '~/Mail'},              #      \u2502    \u2514\u2500\u2500 {maildir_2}\n        ],                                   #      \u2502\n        'mbox': [                            #      \u251c\u2500\u2500 {mbox}\n            {'path': '~/home.mbox'},         #      \u2502    \u251c\u2500\u2500 {mbox_1}\n            {                                #      \u2502    \u251c\u2500\u2500 {mbox_2}\n                'name': 'local',             # <----\u2502----\u2502----\u2514\u2500\u2500 {local}\n                'path': '~/mbox'             #      \u2502    \u2502\n            },                               #      \u2502    \u2502\n            {                                #      \u2502    \u2514\u2500\u2500 {mbox_3}\n                'name': 'debian',            # <----\u2502---------\u2514\u2500\u2500 {debian}\n                'path': '/var/mail/$USER'    #      \u2502\n                'urgent': False,             # <----\u2502---- disable urgent\n            },                               #      \u2502\n        ],                                   #      \u2502\n        'mh': [                              #      \u251c\u2500\u2500 {mh}\n            {'path': '~/mh_mail'},           #      \u2502    \u2514\u2500\u2500 {mh_1}\n        ],                                   #      \u2502\n        'babyl': [                           #      \u251c\u2500\u2500 {babyl}\n            {'path': '~/babyl_mail'},        #      \u2502    \u2514\u2500\u2500 {babyl_1}\n        ],                                   #      \u2502\n        'mmdf': [                            #      \u251c\u2500\u2500 {mmdf}\n            {'path': '~/mmdf_mail'},         #      \u2502    \u2514\u2500\u2500 {mmdf_1}\n        ]                                    #      \u2502\n        'imap': [                            #      \u251c\u2500\u2500 {imap}\n            {                                #      \u2502    \u251c\u2500\u2500 {imap_1}\n                'name': 'home',              # <----\u2502----\u2502----\u2514\u2500\u2500 {home}\n                'user': 'lasers',            #      \u2502    \u2502\n                'password': 'kiss_my_butt!', #      \u2502    \u2502\n                'server': 'imap.gmail.com',  #      \u2502    \u2502\u00a0\n                'port': 993,                 #      \u2502    \u2502\n            },                               #      \u2502    \u2502\n            {                                #      \u2502    \u2514\u2500\u2500 {imap_2}\n                'name': 'work',              # <----\u2502---------\u2514\u2500\u2500 {work}\n                'user': 'tobes',             #      \u2502\n                'password': 'i_love_python', #\n                'server': 'imap.yahoo.com',  #\n                                             # <---- no port, use port 993\n                'urgent': False,             # <---- disable urgent\n            }                                #\n        ]\n    }\n    allow_urgent = False             <---- disable urgent for all accounts\n}\n\n# add colors, disable urgent\nmail {\n    format = '[\\?color=mail&show Mail] {mail}'\n    thresholds = [(1, 'good'), (5, 'degraded'), (15, 'bad')]\n    allow_urgent = False\n}\n\n# identify the mailboxes, remove what you don't need\nmail {\n    format = '[\\?color=mail '\n    format += '[\\?if=imap&color=#00ff00 IMAP ]'\n    format += '[\\?if=maildir&color=#ffff00 MAILDIR ]'\n    format += '[\\?if=mbox&color=#ff0000 MBOX ]'\n    format += '[\\?if=babyl&color=#ffa500 BABYL ]'\n    format += '[\\?if=mmdf&color=#00bfff MMDF ]'\n    format += '[\\?if=mh&color=#ee82ee MH ]'\n    format += ']'\n    format += '[\\?not_zero&color Mail {mail}|No Mail]'\n}\n\n# individual colorized mailboxes, remove what you don't need\nmail {\n    format = '[\\?if=imap&color=#00ff00 IMAP] {imap} '\n    format += '[\\?if=maildir&color=#ffff00 MAILDIR] {maildir} '\n    format += '[\\?if=mbox&color=#ff0000 MBOX] {mbox} '\n    format += '[\\?if=babyl&color=#ffa500 BABYL] {babyl} '\n    format += '[\\?if=mmdf&color=#00bfff MMDF] {mmdf} '\n    format += '[\\?if=mh&color=#ee82ee MH] {mh}'\n    allow_urgent = False\n}\n```\n\n@author lasers\n\nSAMPLE OUTPUT\n{'full_text': 'Mail 15', 'urgent': True}\n\nidentified\n[\n    {'full_text': 'IMAP ', 'color': '#00ff00'},\n    {'full_text': 'MAILDIR ', 'color': '#ffff00'},\n    {'full_text': 'MBOX ', 'color': '#ff0000'},\n    {'full_text': 'Mail 15'},\n]\n\nindividualized\n[\n    {'full_text': 'IMAP ', 'color': '#00ff00'}, {'full_text': 'Mail 10 '},\n    {'full_text': 'MAILDIR ', 'color': '#ffff00'}, {'full_text': 'Mail 2 '},\n    {'full_text': 'MBOX ', 'color': '#ff0000'}, {'full_text': 'Mail 3'},\n]\n\nno_mail\n{'full_text': 'No Mail'}\n\"\"\"\n\nimport mailbox\nfrom imaplib import IMAP4_SSL\nfrom os.path import exists, expanduser, expandvars\nSTRING_MISSING = 'missing {} {}'\nSTRING_WRONG_NAME = 'Accountname ({}) collides with \"Maildir\", \"mbox\", \"mh\", \\\n\"Babyl\", \"MMDF\", \"mail\" or \"IMAP\".'\n\n\nclass Py3status:\n    \"\"\"\n    \"\"\"\n    # available configuration parameters\n    accounts = {}\n    cache_timeout = 60\n    format = '\\?not_zero Mail {mail}|No Mail'\n    thresholds = []\n\n    def post_config_hook(self):\n        if not self.accounts:\n            raise Exception('missing accounts')\n\n        self.mailboxes = {}\n        mailboxes = ['Maildir', 'mbox', 'mh', 'Babyl', 'MMDF', 'IMAP']\n        for mail, accounts in self.accounts.items():\n            if mail not in [x.lower() for x in mailboxes]:\n                continue\n            self.mailboxes[mail] = []\n            for account in accounts:\n                if account['name'] in [x.lower() for x in mailboxes] \\\n                        + ['mail']:\n                    raise Exception(STRING_WRONG_NAME.format(account['name']))\n                account.setdefault('urgent', True)\n                if mail == 'imap':\n                    for v in ['user', 'password', 'server']:\n                        if v not in account:\n                            raise Exception(STRING_MISSING.format(mail, v))\n                    account.setdefault('port', 993)\n                    self.mailboxes[mail].append(account)\n                else:\n                    for box in mailboxes[:-1]:\n                        if mail == box.lower():\n                            if 'path' not in account:\n                                raise Exception(\n                                    STRING_MISSING.format(mail, 'path')\n                                )\n                            path = expandvars(expanduser(account['path']))\n                            if not exists(path):\n                                path = 'path: {}'.format(path)\n                                raise Exception(\n                                    STRING_MISSING.format(mail, path)\n                                )\n                            account['box'] = box\n                            account['path'] = path\n                            self.mailboxes[mail].append(account)\n                            break\n\n        self.thresholds_init = self.py3.get_color_names_list(self.format)\n\n    def mail(self):\n        mail_data = {'mail': 0, 'urgent': False}\n        for k, v in self.mailboxes.items():\n            mail_data[k] = 0\n            for i, account in enumerate(v, 1):\n                if k == 'imap':\n                    inbox = IMAP4_SSL(account['server'], account['port'])\n                    inbox.login(account['user'], account['password'])\n                    inbox.select(readonly=True)\n                    imap_data = inbox.search(None, '(UNSEEN)')\n                    count_mail = len(imap_data[1][0].split())\n                    inbox.close()\n                    inbox.logout()\n                else:\n                    inbox = getattr(mailbox, account['box'])(\n                        account['path'], create=False)\n                    count_mail = len(inbox)\n                    inbox.close()\n                if 'name' in account:\n                    mail_data[account['name']] = count_mail\n                if account['urgent'] and count_mail:\n                    mail_data['urgent'] = True\n                mail_data['%s_%s' % (k, i)] = count_mail\n                mail_data['mail'] += count_mail\n                mail_data[k] += count_mail\n\n        for x in self.thresholds_init:\n            if x in mail_data:\n                self.py3.threshold_get_color(mail_data[x], x)\n\n        response = {\n            'cached_until': self.py3.time_in(self.cache_timeout),\n            'full_text': self.py3.safe_format(self.format, mail_data)\n        }\n        if mail_data['urgent']:\n            response['urgent'] = True\n        return response\n\n\nif __name__ == \"__main__\":\n    \"\"\"\n    Run module in test mode.\n    \"\"\"\n    from py3status.module_test import module_test\n    module_test(Py3status)\n", "path": "py3status/modules/mail.py"}]}