def _create_tag(self, tag_name_or_id, use_existing=True, unique=False, label=False, visible=True, slug=None, icon=None, parent=None): # -> tag ID if tag_name_or_id in self.session.config.tags: # Short circuit if this is a tag ID for an existing tag return tag_name_or_id else: tag_name = tag_name_or_id tags = self.session.config.get_tags(tag_name) if tags and unique: raise ValueError('Tag name is not unique!') elif len(tags) == 1 and use_existing: tag_id = tags[0]._key else: if slug is None: from mailpile.plugins.tags import Slugify if self.my_config.name: slug = Slugify('/'.join([self.my_config.name, tag_name]), tags=self.session.config.tags) else: slug = Slugify(tag_name, tags=self.session.config.tags) tag_id = self.session.config.tags.append({ 'name': tag_name, 'slug': slug, 'type': 'mailbox', 'parent': parent or '', 'label': label, 'flag_allow_add': False, 'flag_allow_del': False, 'icon': icon or 'icon-tag', 'display': 'tag' if visible else 'archive', }) if parent and visible: self.session.config.tags[parent].display = 'tag' return tag_id
def _create_parent_tag(self, save=True): disco_cfg = self.my_config.discovery if disco_cfg.parent_tag: if disco_cfg.parent_tag == '!CREATE': name = (self.my_config.name or (self.my_config.username or '').split('@')[-1] or (disco_cfg.paths and os.path.basename(disco_cfg.paths[0])) or self.my_config._key) if len(name) < 4: name = _('Mail: %s') % name disco_cfg.parent_tag = name if disco_cfg.parent_tag not in self.session.config.tags.keys(): from mailpile.plugins.tags import Slugify disco_cfg.parent_tag = self._create_tag( disco_cfg.parent_tag, use_existing=False, icon='icon-mailsource', slug=Slugify(self.my_config.name, tags=self.session.config.tags), unique=False) if save: self._save_config() return disco_cfg.parent_tag else: return None
def _create_tag(self, tag_name_or_id, use_existing=True, unique=False, parent=None): # -> tag ID if tag_name_or_id in self.session.config.tags: # Short circuit if this is a tag ID for an existing tag return tag_name_or_id else: tag_name = tag_name_or_id tags = self.session.config.get_tags(tag_name) if tags and unique: raise ValueError('Tag name is not unique!') elif len(tags) == 1 and use_existing: tag_id = tags[0]._key elif len(tags) > 1: raise ValueError('Tag name matches multiple tags!') else: from mailpile.plugins.tags import AddTag, Slugify bogus_name = 'New-Tag-%s' % len(str(self.session.config)) AddTag(self.session, arg=[bogus_name]).run(save=False) tags = self.session.config.get_tags(bogus_name) if tags: tags[0].slug = Slugify(tag_name, self.session.config.tags) tags[0].name = tag_name if parent: tags[0].parent = parent tag_id = tags[0]._key else: raise ValueError('Failed to create tag?') return tag_id