package org.noreply.fancydress.directory; import org.noreply.fancydress.directory.parser.*; import org.noreply.fancydress.misc.Util; import org.noreply.fancydress.status.*; import java.util.*; import java.text.ParseException; import java.net.InetAddress; import java.net.UnknownHostException; /** * Base class for both DeliveryMBOXSection and DeliverySMTP Section. * * This is a base class for the DeliveryMBOXSection and the DeliverySMTP class. * Since both are very similar it makes sense to pool their functionality into * a single class from which both inheritate. * * @see ServerDescriptor */ public class DeliveryMBOXSMTPSection { private String name; /* Required */ /** * The version number of this section. */ private String version; /** * The maximum message size (in Kb) that is accepted at this node. */ private int maximumSize; /** * Whether this exit node allows user supplied From: lines. */ private boolean allowFrom; /** * Construct a Delivery/MBOX or Delivery/SMTP section. * * @param section the section to parse. * @throws Mix3BadServerUnrecognizedVersionException if the Version in the section is not recognized. * @throws Mix3BadServerFormatException if the Section is syntactially invalid. */ public DeliveryMBOXSMTPSection(DirectorySection section) throws Mix3BadServerFormatException { name = section.getName(); parseDeliveryMBOXSMTPSection(section); } /** * Parse a Delivery/MBOX or the Delivery/SMTP section. * * @param section the section to parse. * @throws Mix3BadServerUnrecognizedVersionException if the Version in the section is not recognized. * @throws Mix3BadServerFormatException if the Section is syntactially invalid. */ private void parseDeliveryMBOXSMTPSection(DirectorySection section) throws Mix3BadServerFormatException { /* Check Version */ DirectoryEntry entryVersion = section.getEntry("Version"); if (entryVersion == null) throw new Mix3BadServerFormatException("Version not in " + name + " section"); version = entryVersion.getValue(); if (! version.equals("0.1")) /* We have to ignore unknown Versions */ throw new Mix3BadServerUnrecognizedVersionException("Unrecognized " + name + " Version "+version); /* mandatory entries */ DirectoryEntry entryMaximumSize = section.getEntry("Maximum-size"); DirectoryEntry entryAllowFrom = section.getEntry("Allow-From"); /* FIXME if (entryMaximumSize == null) throw new Mix3BadServerFormatException("Maximum-size not in " + name + " section"); */ if (entryAllowFrom == null) throw new Mix3BadServerFormatException("Allow-From not in " + name + " section"); /* FIXME try { Integer p = new Integer(entryMaximumSize.getValue()); maximumSize = p.intValue(); } catch (NumberFormatException e) { throw new Mix3BadServerFormatException("Maximum-size is not a valid integer in " + name + " section", e); }; if (maximumSize < 32) throw new Mix3BadServerFormatException("Maximum-size is smaller than 32 in " + name + " section"); */ try { allowFrom = Util.parseBoolean(entryAllowFrom.getValue()); } catch (ParseException e) { throw new Mix3BadServerFormatException("Allow-From is not a valid boolean in " + name + " section", e); }; } }