001 package com.croftsoft.core.net.news; 002 003 import java.net.*; 004 import java.io.*; 005 import java.util.*; 006 007 import com.croftsoft.core.lang.NullArgumentException; 008 009 /********************************************************************* 010 * USENET (RFC 1036) message manipulation. 011 * 012 * @see 013 * <a target="blank" 014 * href="http://www.w3.org/Protocols/rfc1036/rfc1036.html"> 015 * RFC 1036: Standard for Interchange of USENET Messages</a> 016 * 017 * @author 018 * <a href="https://www.croftsoft.com/">David Wallace Croft</A> 019 * @version 020 * 2001-08-18 021 * @since 022 * 2001-07-27 023 *********************************************************************/ 024 025 public final class UsenetLib 026 ////////////////////////////////////////////////////////////////////// 027 ////////////////////////////////////////////////////////////////////// 028 { 029 030 public static final String PLAIN_TEXT_ONLY_CHARTER_POSTFIX 031 = "Unmarked off-topic materials, binaries, advertising (spam),\r\n" 032 + "excessive posting, cancel attacks, virus infected binaries,\r\n" 033 + "HTML-encoded postings, and abusive cross postings are\r\n" 034 + "prohibited. All posts (messages) must be in plain text only\r\n" 035 + "and be human-readable."; 036 037 /********************************************************************* 038 * Creates a control message to create a new newsgroup. 039 * 040 * @param email 041 * 042 * Your e-mail address. 043 * 044 * @param newsgroup 045 * 046 * See the FAQ for newsgroup naming conventions. 047 * 048 * @param shortDescription 049 * 050 * This plus the newsgroup name should be less than 80 characters. 051 * 052 * @param charter 053 * 054 * May be null. 055 * 056 * @param justification 057 * 058 * May be null. 059 * 060 * @param proponent 061 * 062 * May be null. 063 * 064 * @param isBooster 065 * 066 * True if this is not the first posting of this message. 067 * 068 * @throws IllegalArgumentException 069 * 070 * If the shortDescription is too long. 071 * 072 * @see 073 * "alt.config FAQ" 074 * 075 * @see 076 * "Myths from the new config FAQ" 077 *********************************************************************/ 078 public static UsenetMessage createNewGroupMessage ( 079 String email, 080 String newsgroup, 081 String shortDescription, 082 String charter, 083 String justification, 084 String proponent, 085 boolean isBooster ) 086 ////////////////////////////////////////////////////////////////////// 087 { 088 NullArgumentException.check ( email ); 089 090 NullArgumentException.check ( newsgroup ); 091 092 NullArgumentException.check ( shortDescription ); 093 094 UsenetMessage usenetMessage = new UsenetMessage ( ); 095 096 usenetMessage.setHeader ( 097 UsenetMessage.HEADER_FROM, email ); 098 099 usenetMessage.setHeader ( 100 UsenetMessage.HEADER_NEWSGROUPS, "alt.config,control.newgroup" ); 101 102 usenetMessage.setHeader ( 103 UsenetMessage.HEADER_SUBJECT, "cmsg newgroup " + newsgroup ); 104 105 usenetMessage.setHeader ( 106 UsenetMessage.HEADER_PATH, "" ); 107 108 usenetMessage.setHeader ( 109 UsenetMessage.HEADER_CONTROL, "newgroup " + newsgroup ); 110 111 usenetMessage.setHeader ( 112 UsenetMessage.HEADER_APPROVED, email ); 113 114 StringBuffer stringBuffer = new StringBuffer ( ); 115 116 if ( isBooster ) 117 { 118 stringBuffer.append ( "BOOSTER\r\n\r\n" ); 119 } 120 121 stringBuffer.append ( "For your newsgroups file:\r\n" ); 122 123 String description = newsgroup + '\t' + shortDescription; 124 125 if ( description.length ( ) > 80 ) 126 { 127 throw new IllegalArgumentException ( 128 "shortDescription too long" ); 129 } 130 131 stringBuffer.append ( description ); 132 133 if ( charter != null ) 134 { 135 stringBuffer.append ( "\r\n\r\nCharter\r\n" ); 136 137 stringBuffer.append ( charter ); 138 } 139 140 if ( justification != null ) 141 { 142 stringBuffer.append ( "\r\n\r\nJustification:\r\n" ); 143 144 stringBuffer.append ( justification ); 145 } 146 147 if ( proponent != null ) 148 { 149 stringBuffer.append ( "\r\n\r\nProponent:\r\n" ); 150 151 stringBuffer.append ( proponent ); 152 } 153 154 usenetMessage.setBody ( stringBuffer.toString ( ) ); 155 156 return usenetMessage; 157 } 158 159 ////////////////////////////////////////////////////////////////////// 160 ////////////////////////////////////////////////////////////////////// 161 162 private UsenetLib ( ) { } 163 164 ////////////////////////////////////////////////////////////////////// 165 ////////////////////////////////////////////////////////////////////// 166 }