/*
 * @(#)NntpArticleHeader.java
 *
 * Copyright (c) 2001-2002 JScape
 * 1147 S. 53rd Pl., Mesa, Arizona, 85206, U.S.A.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * JScape. ("Confidential Information").  You shall not disclose such
 * Confidential Information and shall use it only in accordance with
 * the terms of the license agreement you entered into with JScape.
 */
package com.jscape.inet.nntp;

import com.jscape.inet.mime.MimeException;
import com.jscape.inet.mime.MimeMessage;

import java.io.Serializable;

/**
 * Provides methods for constucting, editing and reconstructing a set of NNTP
 * article headers for a given NNTP article.  The NntpArticleHeader class
 * provides a headers only view of an article retreived from an NNTP server.
 */
public class NntpArticleHeader
        extends MimeMessage
        implements Serializable {
    private int id;

    /**
     * Creates a new NntpArticleHeader object.
     */
    public NntpArticleHeader() {
        super();
    }

    /**
     * Creates a new NntpArticleHeader object.
     *
     * @param contents the contents of the article header
     *
     * @throws MimeException if a MIME related parsing error occurs
     */
    public NntpArticleHeader(byte[] contents)
            throws MimeException {
        super(contents);
    }


    /**
     * Gets From header from article headers.
     *
     * @return from
     */
    public String getFrom() {
        return getHeaderValue("From");
    }

    /**
     * Gets Subject header from article headers.
     *
     * @return subject
     */
    public String getSubject() {
        return getHeaderValue("Subject");
    }

    /**
     * Gets Newsgroups header from article headers.
     *
     * @return newsgroups
     */
    public String getNewsgroups() {
        return getHeaderValue("Newsgroups");
    }

    /**
     * Sets unique message id according to NNTP server.
     *
     * @param id the unique message id for this message according to NNTP
     *           server
     */
    protected void setID(int id) {
        this.id = id;
    }

    /**
     * Gets unique message id according to NNTP server.
     * Use this ID when getting the article from the NNTP server.
     *
     * @return id the unique message id for this message according to NNTP
     *         server
     *
     * @see Nntp#getArticle
     */
    public int getID() {
        return id;
    }

    /**
     * Sets Subject header.
     *
     * @param subject the subject
     *
     * @throws MimeException if a MIME related error occurs
     */
    public void setSubject(String subject)
            throws MimeException {
        addReplaceHeader("Subject", subject);
    }

    /**
     * Sets From header.
     *
     * @param from the from address
     *
     * @throws MimeException if a MIME related error occurs
     */
    public void setFrom(String from)
            throws MimeException {
        addReplaceHeader("From", from);
    }

    /**
     * Sets Date header.
     *
     * @param date the date
     *
     * @throws MimeException if a MIME related error occurs
     */
    public void setDate(String date)
            throws MimeException {
        addReplaceHeader("Date", date);
    }

    /**
     * Gets Date header.
     *
     * @return the date
     */
    public String getDate() {
        return getHeaderValue("Date");
    }
}
