Strip the '[Gmail]/' prefix from folder names.

Summary:
T7253 has two related parts:
1. Stripping the '[Gmail]/' prefix from any canonical Gmail folders
2. Handling nested IMAP folders.

This diff fixes 1. Changes for 2. are forthcoming.

Test Plan: Tested manually. Checked that the part was stripped from the N1 folder list.

Reviewers: juan

Reviewed By: juan

Differential Revision: https://phab.nylas.com/D3475
This commit is contained in:
Karim Hamidou 2016-12-01 16:49:09 -08:00
parent d650be5429
commit 15cfe2cec0
3 changed files with 15 additions and 2 deletions

View file

@ -1,4 +1,5 @@
const {DatabaseTypes: {JSONType}} = require('isomorphic-core');
const {formatImapPath} = require('../shared/imap-paths-utils');
module.exports = (sequelize, Sequelize) => {
return sequelize.define('folder', {
@ -32,7 +33,7 @@ module.exports = (sequelize, Sequelize) => {
account_id: this.accountId,
object: 'folder',
name: this.role,
display_name: this.name,
display_name: formatImapPath(this.name),
};
},
},

View file

@ -1,3 +1,5 @@
const {formatImapPath} = require('../shared/imap-paths-utils');
module.exports = (sequelize, Sequelize) => {
return sequelize.define('label', {
id: { type: Sequelize.STRING(65), primaryKey: true },
@ -53,7 +55,7 @@ module.exports = (sequelize, Sequelize) => {
account_id: this.accountId,
object: 'label',
name: this.role,
display_name: this.name,
display_name: formatImapPath(this.name),
};
},
},

View file

@ -0,0 +1,10 @@
function formatImapPath(pathStr) {
if (!pathStr) {
throw new Error("Can not format an empty path!");
}
const s = pathStr.replace(/^\[Gmail\]\//, '');
return s;
}
module.exports = {formatImapPath}