⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jamesimaphost.java

📁 java 开发的邮件服务器平台。支持以下协议。 协议可以修改为自己的专门标识
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    /**     * Partial implementation of list functionality.     * TODO: Handle wildcards anywhere in mailbox pattern     *       (currently only supported as last character of pattern)     * @see org.apache.james.imapserver.ImapHost#listMailboxes     */    private Collection listMailboxes( User user,                                     String mailboxPattern,                                     boolean subscribedOnly )            throws MailboxException    {//        System.out.println( "Listing for user: '" + user.getUserName() + "'" +//                            " pattern:'" + mailboxPattern + "'" );        ArrayList mailboxes = new ArrayList();        String qualifiedPattern = getQualifiedMailboxName( user, mailboxPattern );        Iterator iter = store.listMailboxes( qualifiedPattern ).iterator();        while ( iter.hasNext() ) {            ImapMailbox mailbox = ( ImapMailbox ) iter.next();            // TODO check subscriptions.            if ( subscribedOnly ) {                if ( ! subscriptions.isSubscribed( user, mailbox ) ) {                    // if not subscribed                    mailbox = null;                }            }            // Sets the mailbox to null if it's not viewable.            mailbox = checkViewable( mailbox );            if ( mailbox != null ) {                mailboxes.add( mailbox );            }        }        return mailboxes;    }    /** @see ImapHost#subscribe */    public void subscribe( User user, String mailboxName )            throws MailboxException    {        ImapMailbox mailbox = getMailbox( user, mailboxName, true );        subscriptions.subscribe( user, mailbox );    }    /** @see ImapHost#unsubscribe */    public void unsubscribe( User user, String mailboxName )            throws MailboxException    {        ImapMailbox mailbox = getMailbox( user, mailboxName, true );        subscriptions.unsubscribe( user, mailbox );    }    public int[] expunge( ImapMailbox mailbox )            throws MailboxException    {        ArrayList deletedMessages = new ArrayList();        long[] uids = mailbox.getMessageUids();        for ( int i = 0; i < uids.length; i++ ) {            long uid = uids[i];            SimpleImapMessage message = mailbox.getMessage( uid );            if ( message.getFlags().isDeleted() ) {                deletedMessages.add( message );            }        }        int[] ids = new int[ deletedMessages.size() ];        for ( int i = 0; i < ids.length; i++ ) {            SimpleImapMessage imapMessage = ( SimpleImapMessage ) deletedMessages.get( i );            long uid = imapMessage.getUid();            int msn = mailbox.getMsn( uid );            ids[i] = msn;            mailbox.deleteMessage( uid );        }        return ids;    }    public long[] search( SearchTerm searchTerm, ImapMailbox mailbox )    {        ArrayList matchedMessages = new ArrayList();        long[] allUids = mailbox.getMessageUids();        for ( int i = 0; i < allUids.length; i++ ) {            long uid = allUids[i];            SimpleImapMessage message = mailbox.getMessage( uid );            if ( searchTerm.match( message.getMimeMessage() ) ) {                matchedMessages.add( message );            }        }        long[] matchedUids = new long[ matchedMessages.size() ];        for ( int i = 0; i < matchedUids.length; i++ ) {            SimpleImapMessage imapMessage = ( SimpleImapMessage ) matchedMessages.get( i );            long uid = imapMessage.getUid();            matchedUids[i] = uid;        }        return matchedUids;    }    /** @see {@link ImapHost#copyMessage } */    public void copyMessage( long uid, ImapMailbox currentMailbox, ImapMailbox toMailbox )            throws MailboxException    {        SimpleImapMessage originalMessage = currentMailbox.getMessage( uid );        MimeMessage newMime = null;        try {            newMime = new MimeMessage( originalMessage.getMimeMessage() );        }        catch ( MessagingException e ) {            // TODO chain.            throw new MailboxException( "Messaging exception: " + e.getMessage() );        }        MessageFlags newFlags = new MessageFlags();        newFlags.setAll( originalMessage.getFlags() );        Date newDate = originalMessage.getInternalDate();        toMailbox.createMessage( newMime, newFlags, newDate);    }    /**     * Convert a user specified mailbox name into a server absolute name.     * If the mailboxName begins with the namespace token,     * return as-is.     * If not, need to resolve the Mailbox name for this user.     * Example:     * <br> Convert "INBOX" for user "Fred.Flinstone" into     * absolute name: "#user.Fred.Flintstone.INBOX"     *     * @return String of absoluteName, null if not valid selection     */    private String getQualifiedMailboxName( User user, String mailboxName )    {        String userName = user.getUserName();        if ( "INBOX".equalsIgnoreCase( mailboxName ) ) {            return USER_NAMESPACE + HIERARCHY_DELIMITER + userName +                    HIERARCHY_DELIMITER + INBOX_NAME;        }        if ( mailboxName.startsWith( NAMESPACE_PREFIX ) ) {            return mailboxName;        }        else {            if ( mailboxName.length() == 0 ) {                return USER_NAMESPACE + HIERARCHY_DELIMITER + userName;            }            else {                return USER_NAMESPACE + HIERARCHY_DELIMITER + userName +                        HIERARCHY_DELIMITER + mailboxName;            }        }    }    /**     * Handles all user subscriptions.     * TODO make this a proper class     * TODO persist     */    private class MailboxSubscriptions    {        private Map userSubs = new HashMap();        /**         * Subscribes the user to the mailbox.         * TODO should this fail if already subscribed?         * @param user The user making the subscription         * @param mailbox The mailbox to subscribe         * @throws MailboxException ??? doesn't yet.         */        void subscribe( User user, ImapMailbox mailbox )                throws MailboxException        {            getUserSubs( user ).add( mailbox.getFullName() );        }        /**         * Unsubscribes the user from this mailbox.         * TODO should this fail if not already subscribed?         * @param user The user making the request.         * @param mailbox The mailbox to unsubscribe         * @throws MailboxException ?? doesn't yet         */        void unsubscribe( User user, ImapMailbox mailbox )                throws MailboxException        {            getUserSubs( user ).remove( mailbox.getFullName() );        }        /**         * Returns whether the user is subscribed to the specified mailbox.         * @param user The user to test.         * @param mailbox The mailbox to test.         * @return <code>true</code> if the user is subscribed.         */        boolean isSubscribed( User user, ImapMailbox mailbox )        {            return getUserSubs( user ).contains( mailbox.getFullName() );        }        private Collection getUserSubs( User user )        {            Collection subs = (Collection)userSubs.get( user.getUserName() );            if ( subs == null ) {                subs = new ArrayList();                userSubs.put( user.getUserName(), subs );            }            return subs;        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -