Decode UTF7 special characters in folder / label names #9

This commit is contained in:
Ben Gotow 2017-10-03 14:12:49 -07:00
parent 7864b3b824
commit 37cd1a8c60
3 changed files with 12 additions and 4 deletions

View file

@ -74,6 +74,7 @@
"tld": "^0.0.2",
"underscore": "1.8.x",
"underscore.string": "^3.0",
"utf7": "^1.0.2",
"windows-shortcuts": "emorikawa/windows-shortcuts#b0a0fc7"
},
"optionalDependencies": {

View file

@ -25,6 +25,10 @@ describe 'Category classes', ->
foo = new Folder({path: 'INBOX'})
expect(foo.displayName).toEqual('Inbox')
it "should convert the UTF7-formatted path back to UTF8", ->
foo = new Label({path: 'T&AOk-st F&APg-reign L&AOU-bel'})
expect(foo.displayName).toEqual('Tést Føreign Låbel')
describe 'category types', ->
it 'assigns type correctly when it is a user category', ->
cat = new Label

View file

@ -1,4 +1,5 @@
/* eslint global-require: 0 */
import utf7 from 'utf7';
import Model from './model';
import Attributes from '../attributes';
@ -57,15 +58,17 @@ Section: Models
*/
export default class Category extends Model {
get displayName() {
const decoded = utf7.imap.decode(this.path);
for (const prefix of ['INBOX', '[Gmail]', '[Mailspring]']) {
if (this.path.startsWith(prefix) && this.path.length > prefix.length + 1) {
return this.path.substr(prefix.length + 1); // + delimiter
if (decoded.startsWith(prefix) && decoded.length > prefix.length + 1) {
return decoded.substr(prefix.length + 1); // + delimiter
}
}
if (this.path === 'INBOX') {
if (decoded === 'INBOX') {
return 'Inbox';
}
return this.path;
return decoded;
}
/* Available for historical reasons, do not use. */