POP3MessageInfo.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      https://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */

  17. package org.apache.commons.net.pop3;

  18. /**
  19.  * POP3MessageInfo is used to return information about messages stored on a POP3 server. Its fields are used to mean slightly different things depending on the
  20.  * information being returned.
  21.  * <p>
  22.  * In response to a status command, {@code number} contains the number of messages in the mailbox, {@code size} contains the size of the mailbox
  23.  * in bytes, and {@code identifier} is null.
  24.  * </p>
  25.  * <p>
  26.  * In response to a message listings, {@code number} contains the message number, {@code size} contains the size of the message in bytes, and
  27.  * {@code identifier} is null.
  28.  * </p>
  29.  * <p>
  30.  * In response to unique identifier listings, {@code number} contains the message number, {@code size} is undefined, and {@code identifier}
  31.  * contains the message's unique identifier.
  32.  * </p>
  33.  */
  34. public final class POP3MessageInfo {

  35.     /** Number. */
  36.     public int number;

  37.     /** Size. */
  38.     public int size;

  39.     /** Identifier. */
  40.     public String identifier;

  41.     /**
  42.      * Constructs a new instance with {@code number} and {@code size} set to 0, and {@code identifier} set to null.
  43.      */
  44.     public POP3MessageInfo() {
  45.         this(0, null, 0);
  46.     }

  47.     /**
  48.      * Constructs a new instance with {@code number} set to {@code num}, {@code size} set to {@code octets}, and
  49.      * {@code identifier} set to null.
  50.      *
  51.      * @param num    the number
  52.      * @param octets the size
  53.      */
  54.     public POP3MessageInfo(final int num, final int octets) {
  55.         this(num, null, octets);
  56.     }

  57.     /**
  58.      * Constructs a new instance with {@code number} set to {@code num}, {@code size} undefined, and {@code identifier} set to
  59.      * {@code uid}.
  60.      *
  61.      * @param num the number
  62.      * @param uid the UID
  63.      */
  64.     public POP3MessageInfo(final int num, final String uid) {
  65.         this(num, uid, -1);
  66.     }

  67.     /**
  68.      * Constructs a new instance.
  69.      *
  70.      * @param num    the number.
  71.      * @param uid    the UID.
  72.      * @param octets the size.
  73.      */
  74.     private POP3MessageInfo(final int num, final String uid, final int size) {
  75.         this.number = num;
  76.         this.size = size;
  77.         this.identifier = uid;
  78.     }

  79.     /**
  80.      * @since 3.6
  81.      */
  82.     @Override
  83.     public String toString() {
  84.         return "Number: " + number + ". Size: " + size + ". Id: " + identifier;
  85.     }
  86. }