You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jl...@apache.org on 2022/05/03 12:22:12 UTC
svn commit: r1900504 [14/22] - in /geronimo/specs/trunk: ./ geronimo-activation_2.0_spec/ geronimo-activation_2.0_spec/src/ geronimo-activation_2.0_spec/src/main/ geronimo-activation_2.0_spec/src/main/java/ geronimo-activation_2.0_spec/src/main/java/ja...
Added: geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/internet/ParseException.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/internet/ParseException.java?rev=1900504&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/internet/ParseException.java (added)
+++ geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/internet/ParseException.java Tue May 3 12:22:08 2022
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package jakarta.mail.internet;
+
+import jakarta.mail.MessagingException;
+
+/**
+ * @version $Rev$ $Date$
+ * The exception thrown due to an error in parsing RFC822
+ * or MIME headers, including multipart bodies.
+ */
+public class ParseException extends MessagingException {
+
+ private static final long serialVersionUID = 7649991205183658089L;
+
+ public ParseException() {
+ super();
+ }
+
+ public ParseException(final String message) {
+ super(message);
+ }
+}
Added: geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/internet/PreencodedMimeBodyPart.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/internet/PreencodedMimeBodyPart.java?rev=1900504&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/internet/PreencodedMimeBodyPart.java (added)
+++ geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/internet/PreencodedMimeBodyPart.java Tue May 3 12:22:08 2022
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package jakarta.mail.internet;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import jakarta.mail.MessagingException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+
+
+public class PreencodedMimeBodyPart extends MimeBodyPart {
+ // the defined transfer encoding
+ private final String transferEncoding;
+
+
+ /**
+ * Create a new body part with the specified MIME transfer encoding.
+ *
+ * @param encoding The content encoding.
+ */
+ public PreencodedMimeBodyPart(final String encoding) {
+ transferEncoding = encoding;
+ }
+
+
+ /**
+ * Retieve the defined encoding for this body part.
+ *
+ * @return
+ * @exception MessagingException
+ */
+ @Override
+ public String getEncoding() throws MessagingException {
+ return transferEncoding;
+ }
+
+ /**
+ * Write the body part content to the stream without applying
+ * and additional encodings.
+ *
+ * @param out The target output stream.
+ *
+ * @exception IOException
+ * @exception MessagingException
+ */
+ @Override
+ public void writeTo(final OutputStream out) throws IOException, MessagingException {
+ headers.writeTo(out, null);
+ // add the separater between the headers and the data portion.
+ out.write('\r');
+ out.write('\n');
+ // write this out without getting an encoding stream
+ getDataHandler().writeTo(out);
+ out.flush();
+ }
+
+
+ /**
+ * Override of update headers to ensure the transfer encoding
+ * is forced to the correct type.
+ *
+ * @exception MessagingException
+ */
+ @Override
+ protected void updateHeaders() throws MessagingException {
+ super.updateHeaders();
+ setHeader("Content-Transfer-Encoding", transferEncoding);
+ }
+}
+
Added: geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/internet/SharedInputStream.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/internet/SharedInputStream.java?rev=1900504&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/internet/SharedInputStream.java (added)
+++ geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/internet/SharedInputStream.java Tue May 3 12:22:08 2022
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package jakarta.mail.internet;
+
+import java.io.InputStream;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface SharedInputStream {
+ public abstract long getPosition();
+
+ public abstract InputStream newStream(long start, long end);
+}
Added: geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/AddressStringTerm.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/AddressStringTerm.java?rev=1900504&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/AddressStringTerm.java (added)
+++ geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/AddressStringTerm.java Tue May 3 12:22:08 2022
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package jakarta.mail.search;
+
+import jakarta.mail.Address;
+
+/**
+ * A Term that compares two Addresses as Strings.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class AddressStringTerm extends StringTerm {
+
+ private static final long serialVersionUID = 3086821234204980368L;
+
+ /**
+ * Constructor.
+ * @param pattern the pattern to be compared
+ */
+ protected AddressStringTerm(final String pattern) {
+ super(pattern);
+ }
+
+ /**
+ * Tests if the patterm associated with this Term is a substring of
+ * the address in the supplied object.
+ *
+ * @param address
+ * @return
+ */
+ protected boolean match(final Address address) {
+ return match(address.toString());
+ }
+}
Added: geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/AddressTerm.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/AddressTerm.java?rev=1900504&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/AddressTerm.java (added)
+++ geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/AddressTerm.java Tue May 3 12:22:08 2022
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package jakarta.mail.search;
+
+import jakarta.mail.Address;
+
+/**
+ * Term that compares two addresses.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class AddressTerm extends SearchTerm {
+
+ private static final long serialVersionUID = 2005405551929769980L;
+
+ /**
+ * The address.
+ */
+ protected Address address;
+
+ /**
+ * Constructor taking the address for this term.
+ * @param address the address
+ */
+ protected AddressTerm(final Address address) {
+ this.address = address;
+ }
+
+ /**
+ * Return the address of this term.
+ *
+ * @return the addre4ss
+ */
+ public Address getAddress() {
+ return address;
+ }
+
+ /**
+ * Match to the supplied address.
+ *
+ * @param address the address to match with
+ * @return true if the addresses match
+ */
+ protected boolean match(final Address address) {
+ return this.address.equals(address);
+ }
+
+ @Override
+ public boolean equals(final Object other) {
+ if (this == other) {
+ return true;
+ }
+ if (other instanceof AddressTerm == false) {
+ return false;
+ }
+
+ return address.equals(((AddressTerm) other).address);
+ }
+
+ @Override
+ public int hashCode() {
+ return address.hashCode();
+ }
+}
Added: geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/AndTerm.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/AndTerm.java?rev=1900504&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/AndTerm.java (added)
+++ geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/AndTerm.java Tue May 3 12:22:08 2022
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package jakarta.mail.search;
+
+import java.util.Arrays;
+
+import jakarta.mail.Message;
+
+/**
+ * Term that implements a logical AND across terms.
+ *
+ * @version $Rev$ $Date$
+ */
+public final class AndTerm extends SearchTerm {
+
+ private static final long serialVersionUID = -3583274505380989582L;
+
+ /**
+ * Terms to which the AND operator should be applied.
+ */
+ private final SearchTerm[] terms;
+
+ /**
+ * Constructor for performing a binary AND.
+ *
+ * @param a the first term
+ * @param b the second ter,
+ */
+ public AndTerm(final SearchTerm a, final SearchTerm b) {
+ terms = new SearchTerm[]{a, b};
+ }
+
+ /**
+ * Constructor for performing and AND across an arbitraty number of terms.
+ * @param terms the terms to AND together
+ */
+ public AndTerm(final SearchTerm[] terms) {
+ this.terms = terms;
+ }
+
+ /**
+ * Return the terms.
+ * @return the terms
+ */
+ public SearchTerm[] getTerms() {
+ return terms;
+ }
+
+ /**
+ * Match by applying the terms, in order, to the Message and performing an AND operation
+ * to the result. Comparision will stop immediately if one of the terms returns false.
+ *
+ * @param message the Message to apply the terms to
+ * @return true if all terms match
+ */
+ @Override
+ public boolean match(final Message message) {
+ for (int i = 0; i < terms.length; i++) {
+ final SearchTerm term = terms[i];
+ if (!term.match(message)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public boolean equals(final Object other) {
+ if (other == this) {
+ return true;
+ }
+ if (other instanceof AndTerm == false) {
+ return false;
+ }
+ return Arrays.equals(terms, ((AndTerm) other).terms);
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 0;
+ for (int i = 0; i < terms.length; i++) {
+ hash = hash * 37 + terms[i].hashCode();
+ }
+ return hash;
+ }
+}
Added: geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/BodyTerm.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/BodyTerm.java?rev=1900504&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/BodyTerm.java (added)
+++ geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/BodyTerm.java Tue May 3 12:22:08 2022
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package jakarta.mail.search;
+
+import java.io.IOException;
+
+import jakarta.mail.BodyPart;
+import jakarta.mail.Message;
+import jakarta.mail.MessagingException;
+import jakarta.mail.Multipart;
+import jakarta.mail.Part;
+
+/**
+ * Term that matches on a message body. All {@link BodyPart parts} that have
+ * a MIME type of "text/*" are searched.
+ *
+ * @version $Rev$ $Date$
+ */
+public final class BodyTerm extends StringTerm {
+
+ private static final long serialVersionUID = -4888862527916911385L;
+
+ public BodyTerm(final String pattern) {
+ super(pattern);
+ }
+
+ @Override
+ public boolean match(final Message message) {
+ try {
+ return matchPart(message);
+ } catch (final IOException e) {
+ return false;
+ } catch (final MessagingException e) {
+ return false;
+ }
+ }
+
+ private boolean matchPart(final Part part) throws MessagingException, IOException {
+ if (part.isMimeType("multipart/*")) {
+ final Multipart mp = (Multipart) part.getContent();
+ final int count = mp.getCount();
+ for (int i=0; i < count; i++) {
+ final BodyPart bp = mp.getBodyPart(i);
+ if (matchPart(bp)) {
+ return true;
+ }
+ }
+ return false;
+ } else if (part.isMimeType("text/*")) {
+ final String content = (String) part.getContent();
+ return super.match(content);
+ } else if (part.isMimeType("message/rfc822")) {
+ // nested messages need recursion
+ return matchPart((Part)part.getContent());
+ } else {
+ return false;
+ }
+ }
+}
Added: geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/ComparisonTerm.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/ComparisonTerm.java?rev=1900504&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/ComparisonTerm.java (added)
+++ geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/ComparisonTerm.java Tue May 3 12:22:08 2022
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package jakarta.mail.search;
+
+/**
+ * Base for comparison terms.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class ComparisonTerm extends SearchTerm {
+
+ private static final long serialVersionUID = 1456646953666474308L;
+
+ public static final int LE = 1;
+ public static final int LT = 2;
+ public static final int EQ = 3;
+ public static final int NE = 4;
+ public static final int GT = 5;
+ public static final int GE = 6;
+
+ protected int comparison;
+
+ public ComparisonTerm() {
+ }
+
+ @Override
+ public boolean equals(final Object other) {
+ if (!(other instanceof ComparisonTerm)) {
+ return false;
+ }
+ return comparison == ((ComparisonTerm)other).comparison;
+ }
+
+ @Override
+ public int hashCode() {
+ return comparison;
+ }
+}
Added: geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/DateTerm.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/DateTerm.java?rev=1900504&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/DateTerm.java (added)
+++ geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/DateTerm.java Tue May 3 12:22:08 2022
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package jakarta.mail.search;
+
+import java.util.Date;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public abstract class DateTerm extends ComparisonTerm {
+
+ private static final long serialVersionUID = 4818873430063720043L;
+ protected Date date;
+
+ protected DateTerm(final int comparison, final Date date) {
+ super();
+ this.comparison = comparison;
+ this.date = date;
+ }
+
+ public Date getDate() {
+ return date;
+ }
+
+ public int getComparison() {
+ return comparison;
+ }
+
+ protected boolean match(final Date match) {
+ final long matchTime = match.getTime();
+ final long mytime = date.getTime();
+ switch (comparison) {
+ case EQ:
+ return matchTime == mytime;
+ case NE:
+ return matchTime != mytime;
+ case LE:
+ return matchTime <= mytime;
+ case LT:
+ return matchTime < mytime;
+ case GT:
+ return matchTime > mytime;
+ case GE:
+ return matchTime >= mytime;
+ default:
+ return false;
+ }
+ }
+
+ @Override
+ public boolean equals(final Object other) {
+ if (other == this) {
+ return true;
+ }
+ if (other instanceof DateTerm == false) {
+ return false;
+ }
+ final DateTerm term = (DateTerm) other;
+ return this.comparison == term.comparison && this.date.equals(term.date);
+ }
+
+ @Override
+ public int hashCode() {
+ return date.hashCode() + super.hashCode();
+ }
+}
Added: geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/FlagTerm.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/FlagTerm.java?rev=1900504&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/FlagTerm.java (added)
+++ geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/FlagTerm.java Tue May 3 12:22:08 2022
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package jakarta.mail.search;
+
+import jakarta.mail.Flags;
+import jakarta.mail.Message;
+import jakarta.mail.MessagingException;
+
+/**
+ * Term for matching message {@link Flags}.
+ *
+ * @version $Rev$ $Date$
+ */
+public final class FlagTerm extends SearchTerm {
+
+ private static final long serialVersionUID = -142991500302030647L;
+
+ /**
+ * If true, test that all flags are set; if false, test that all flags are clear.
+ */
+ private final boolean set;
+ /**
+ * The flags to test.
+ */
+ private final Flags flags;
+
+ /**
+ * @param flags the flags to test
+ * @param set test for set or clear; {@link #set}
+ */
+ public FlagTerm(final Flags flags, final boolean set) {
+ this.set = set;
+ this.flags = flags;
+ }
+
+ public Flags getFlags() {
+ return flags;
+ }
+
+ public boolean getTestSet() {
+ return set;
+ }
+
+ @Override
+ public boolean match(final Message message) {
+ try {
+ final Flags msgFlags = message.getFlags();
+ if (set) {
+ return msgFlags.contains(flags);
+ } else {
+ // yuk - I wish we could get at the internal state of the Flags
+ final Flags.Flag[] system = flags.getSystemFlags();
+ for (int i = 0; i < system.length; i++) {
+ final Flags.Flag flag = system[i];
+ if (msgFlags.contains(flag)) {
+ return false;
+ }
+ }
+ final String[] user = flags.getUserFlags();
+ for (int i = 0; i < user.length; i++) {
+ final String flag = user[i];
+ if (msgFlags.contains(flag)) {
+ return false;
+ }
+ }
+ return true;
+ }
+ } catch (final MessagingException e) {
+ return false;
+ }
+ }
+
+ @Override
+ public boolean equals(final Object other) {
+ if (other == this) {
+ return true;
+ }
+ if (other instanceof FlagTerm == false) {
+ return false;
+ }
+ final FlagTerm otherFlags = (FlagTerm) other;
+ return otherFlags.set == this.set && otherFlags.flags.equals(flags);
+ }
+
+ @Override
+ public int hashCode() {
+ return set ? flags.hashCode() : ~flags.hashCode();
+ }
+}
Added: geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/FromStringTerm.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/FromStringTerm.java?rev=1900504&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/FromStringTerm.java (added)
+++ geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/FromStringTerm.java Tue May 3 12:22:08 2022
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package jakarta.mail.search;
+
+import jakarta.mail.Address;
+import jakarta.mail.Message;
+import jakarta.mail.MessagingException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public final class FromStringTerm extends AddressStringTerm {
+
+ private static final long serialVersionUID = 5801127523826772788L;
+
+ public FromStringTerm(final String string) {
+ super(string);
+ }
+
+ @Override
+ public boolean match(final Message message) {
+ try {
+ final Address from[] = message.getFrom();
+ if (from == null) {
+ return false;
+ }
+
+ for (int i = 0; i < from.length; i++) {
+ if (match(from[i])){
+ return true;
+ }
+ }
+ return false;
+ } catch (final MessagingException e) {
+ return false;
+ }
+ }
+}
Added: geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/FromTerm.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/FromTerm.java?rev=1900504&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/FromTerm.java (added)
+++ geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/FromTerm.java Tue May 3 12:22:08 2022
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package jakarta.mail.search;
+
+import jakarta.mail.Address;
+import jakarta.mail.Message;
+import jakarta.mail.MessagingException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public final class FromTerm extends AddressTerm {
+
+ private static final long serialVersionUID = 5214730291502658665L;
+
+ public FromTerm(final Address match) {
+ super(match);
+ }
+
+ @Override
+ public boolean match(final Message message) {
+ try {
+ final Address from[] = message.getFrom();
+ if (from == null) {
+ return false;
+ }
+ for (int i = 0; i < from.length; i++) {
+ if (match(from[i])) {
+ return true;
+ }
+ }
+ return false;
+ } catch (final MessagingException e) {
+ return false;
+ }
+ }
+}
Added: geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/HeaderTerm.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/HeaderTerm.java?rev=1900504&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/HeaderTerm.java (added)
+++ geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/HeaderTerm.java Tue May 3 12:22:08 2022
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package jakarta.mail.search;
+
+import jakarta.mail.Message;
+import jakarta.mail.MessagingException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public final class HeaderTerm extends StringTerm {
+
+ private static final long serialVersionUID = 8342514650333389122L;
+
+ private final String headerName;
+
+ public HeaderTerm(final String header, final String pattern) {
+ super(pattern);
+ this.headerName = header;
+ }
+
+ public String getHeaderName() {
+ return headerName;
+ }
+
+ @Override
+ public boolean match(final Message message) {
+ try {
+ final String values[] = message.getHeader(headerName);
+ if (values != null) {
+ for (int i = 0; i < values.length; i++) {
+ final String value = values[i];
+ if (match(value)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ } catch (final MessagingException e) {
+ return false;
+ }
+ }
+
+ @Override
+ public boolean equals(final Object other) {
+ if (other == this) {
+ return true;
+ }
+ if (other instanceof HeaderTerm == false) {
+ return false;
+ }
+ // we need to compare with more than just the header name.
+ return headerName.equalsIgnoreCase(((HeaderTerm) other).headerName) && super.equals(other);
+ }
+
+ @Override
+ public int hashCode() {
+ return headerName.toLowerCase().hashCode() + super.hashCode();
+ }
+}
Added: geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/IntegerComparisonTerm.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/IntegerComparisonTerm.java?rev=1900504&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/IntegerComparisonTerm.java (added)
+++ geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/IntegerComparisonTerm.java Tue May 3 12:22:08 2022
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package jakarta.mail.search;
+
+/**
+ * A Term that provides comparisons for integers.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class IntegerComparisonTerm extends ComparisonTerm {
+
+ private static final long serialVersionUID = -6963571240154302484L;
+
+ protected int number;
+
+ protected IntegerComparisonTerm(final int comparison, final int number) {
+ super();
+ this.comparison = comparison;
+ this.number = number;
+ }
+
+ public int getNumber() {
+ return number;
+ }
+
+ public int getComparison() {
+ return comparison;
+ }
+
+ protected boolean match(final int match) {
+ switch (comparison) {
+ case EQ:
+ return match == number;
+ case NE:
+ return match != number;
+ case GT:
+ return match > number;
+ case GE:
+ return match >= number;
+ case LT:
+ return match < number;
+ case LE:
+ return match <= number;
+ default:
+ return false;
+ }
+ }
+
+ @Override
+ public boolean equals(final Object other) {
+ if (other == this) {
+ return true;
+ }
+ if (other instanceof IntegerComparisonTerm == false) {
+ return false;
+ }
+ final IntegerComparisonTerm term = (IntegerComparisonTerm) other;
+ return this.comparison == term.comparison && this.number == term.number;
+ }
+
+ @Override
+ public int hashCode() {
+ return number + super.hashCode();
+ }
+}
Added: geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/MessageIDTerm.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/MessageIDTerm.java?rev=1900504&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/MessageIDTerm.java (added)
+++ geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/MessageIDTerm.java Tue May 3 12:22:08 2022
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package jakarta.mail.search;
+
+import jakarta.mail.Message;
+import jakarta.mail.MessagingException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public final class MessageIDTerm extends StringTerm {
+
+
+ private static final long serialVersionUID = -2121096296454691963L;
+
+ public MessageIDTerm(final String id) {
+ super(id);
+ }
+
+ @Override
+ public boolean match(final Message message) {
+ try {
+ final String values[] = message.getHeader("Message-ID");
+ if (values != null) {
+ for (int i = 0; i < values.length; i++) {
+ final String value = values[i];
+ if (match(value)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ } catch (final MessagingException e) {
+ return false;
+ }
+ }
+
+ @Override
+ public boolean equals(final Object other) {
+ if (!(other instanceof MessageIDTerm)) {
+ return false;
+ }
+ return super.equals(other);
+ }
+}
Added: geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/MessageNumberTerm.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/MessageNumberTerm.java?rev=1900504&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/MessageNumberTerm.java (added)
+++ geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/MessageNumberTerm.java Tue May 3 12:22:08 2022
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package jakarta.mail.search;
+
+import jakarta.mail.Message;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public final class MessageNumberTerm extends IntegerComparisonTerm {
+
+ private static final long serialVersionUID = -5379625829658623812L;
+
+ public MessageNumberTerm(final int number) {
+ super(EQ, number);
+ }
+
+ @Override
+ public boolean match(final Message message) {
+ return match(message.getMessageNumber());
+ }
+
+ @Override
+ public boolean equals(final Object other) {
+ if (!(other instanceof MessageNumberTerm)) {
+ return false;
+ }
+ return super.equals(other);
+ }
+}
Added: geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/NotTerm.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/NotTerm.java?rev=1900504&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/NotTerm.java (added)
+++ geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/NotTerm.java Tue May 3 12:22:08 2022
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package jakarta.mail.search;
+
+import jakarta.mail.Message;
+
+/**
+ * Term that implements a logical negation.
+ *
+ * @version $Rev$ $Date$
+ */
+public final class NotTerm extends SearchTerm {
+
+ private static final long serialVersionUID = 7152293214217310216L;
+
+ private final SearchTerm term;
+
+ public NotTerm(final SearchTerm term) {
+ this.term = term;
+ }
+
+ public SearchTerm getTerm() {
+ return term;
+ }
+
+ @Override
+ public boolean match(final Message message) {
+ return !term.match(message);
+ }
+
+ @Override
+ public boolean equals(final Object other) {
+ if (other == this) {
+ return true;
+ }
+ if (other instanceof NotTerm == false) {
+ return false;
+ }
+ return term.equals(((NotTerm) other).term);
+ }
+
+ @Override
+ public int hashCode() {
+ return term.hashCode();
+ }
+}
Added: geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/OrTerm.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/OrTerm.java?rev=1900504&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/OrTerm.java (added)
+++ geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/OrTerm.java Tue May 3 12:22:08 2022
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package jakarta.mail.search;
+
+import java.util.Arrays;
+
+import jakarta.mail.Message;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public final class OrTerm extends SearchTerm {
+
+ private static final long serialVersionUID = 5380534067523646936L;
+
+ private final SearchTerm[] terms;
+
+ public OrTerm(final SearchTerm a, final SearchTerm b) {
+ terms = new SearchTerm[]{a, b};
+ }
+
+ public OrTerm(final SearchTerm[] terms) {
+ this.terms = terms;
+ }
+
+ public SearchTerm[] getTerms() {
+ return terms;
+ }
+
+ @Override
+ public boolean match(final Message message) {
+ for (int i = 0; i < terms.length; i++) {
+ final SearchTerm term = terms[i];
+ if (term.match(message)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public boolean equals(final Object other) {
+ if (other == this) {
+ return true;
+ }
+ if (other instanceof OrTerm == false) {
+ return false;
+ }
+ return Arrays.equals(terms, ((OrTerm) other).terms);
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 0;
+ for (int i = 0; i < terms.length; i++) {
+ hash = hash * 37 + terms[i].hashCode();
+ }
+ return hash;
+ }
+}
Added: geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/ReceivedDateTerm.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/ReceivedDateTerm.java?rev=1900504&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/ReceivedDateTerm.java (added)
+++ geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/ReceivedDateTerm.java Tue May 3 12:22:08 2022
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package jakarta.mail.search;
+
+import java.util.Date;
+
+import jakarta.mail.Message;
+import jakarta.mail.MessagingException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public final class ReceivedDateTerm extends DateTerm {
+
+ private static final long serialVersionUID = -2756695246195503170L;
+
+ public ReceivedDateTerm(final int comparison, final Date date) {
+ super(comparison, date);
+ }
+
+ @Override
+ public boolean match(final Message message) {
+ try {
+ final Date date = message.getReceivedDate();
+ if (date == null) {
+ return false;
+ }
+
+ return match(date);
+ } catch (final MessagingException e) {
+ return false;
+ }
+ }
+
+
+ @Override
+ public boolean equals(final Object other) {
+ if (other == this) {
+ return true;
+ }
+ if (other instanceof ReceivedDateTerm == false) {
+ return false;
+ }
+ return super.equals(other);
+ }
+}
Added: geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/RecipientStringTerm.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/RecipientStringTerm.java?rev=1900504&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/RecipientStringTerm.java (added)
+++ geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/RecipientStringTerm.java Tue May 3 12:22:08 2022
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package jakarta.mail.search;
+
+import jakarta.mail.Address;
+import jakarta.mail.Message;
+import jakarta.mail.MessagingException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public final class RecipientStringTerm extends AddressStringTerm {
+
+ private static final long serialVersionUID = -8293562089611618849L;
+
+ private final Message.RecipientType type;
+
+ public RecipientStringTerm(final Message.RecipientType type, final String pattern) {
+ super(pattern);
+ this.type = type;
+ }
+
+ public Message.RecipientType getRecipientType() {
+ return type;
+ }
+
+ @Override
+ public boolean match(final Message message) {
+ try {
+ final Address from[] = message.getRecipients(type);
+ if (from == null) {
+ return false;
+ }
+ for (int i = 0; i < from.length; i++) {
+ final Address address = from[i];
+ if (match(address)) {
+ return true;
+ }
+ }
+ return false;
+ } catch (final MessagingException e) {
+ return false;
+ }
+ }
+
+ @Override
+ public boolean equals(final Object other) {
+ if (other == this) {
+ return true;
+ }
+ if (other instanceof RecipientStringTerm == false) {
+ return false;
+ }
+ final RecipientStringTerm otherTerm = (RecipientStringTerm) other;
+ return this.pattern.equals(otherTerm.pattern) && this.type == otherTerm.type;
+ }
+
+ @Override
+ public int hashCode() {
+ return pattern.hashCode() + type.hashCode();
+ }
+}
Added: geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/RecipientTerm.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/RecipientTerm.java?rev=1900504&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/RecipientTerm.java (added)
+++ geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/RecipientTerm.java Tue May 3 12:22:08 2022
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package jakarta.mail.search;
+
+import jakarta.mail.Address;
+import jakarta.mail.Message;
+import jakarta.mail.MessagingException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public final class RecipientTerm extends AddressTerm {
+
+
+ private static final long serialVersionUID = 6548700653122680468L;
+
+ private final Message.RecipientType type;
+
+ public RecipientTerm(final Message.RecipientType type, final Address address) {
+ super(address);
+ this.type = type;
+ }
+
+ public Message.RecipientType getRecipientType() {
+ return type;
+ }
+
+ @Override
+ public boolean match(final Message message) {
+ try {
+ final Address from[] = message.getRecipients(type);
+ if (from == null) {
+ return false;
+ }
+ for (int i = 0; i < from.length; i++) {
+ final Address address = from[i];
+ if (match(address)) {
+ return true;
+ }
+ }
+ return false;
+ } catch (final MessagingException e) {
+ return false;
+ }
+ }
+
+ @Override
+ public boolean equals(final Object other) {
+ if (this == other) {
+ return true;
+ }
+ if (other instanceof RecipientTerm == false) {
+ return false;
+ }
+
+ final RecipientTerm recipientTerm = (RecipientTerm) other;
+ return address.equals(recipientTerm.address) && type == recipientTerm.type;
+ }
+
+ @Override
+ public int hashCode() {
+ return address.hashCode() + type.hashCode();
+ }
+}
Added: geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/SearchException.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/SearchException.java?rev=1900504&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/SearchException.java (added)
+++ geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/SearchException.java Tue May 3 12:22:08 2022
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package jakarta.mail.search;
+
+import jakarta.mail.MessagingException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SearchException extends MessagingException {
+
+ private static final long serialVersionUID = -7092886778226268686L;
+
+ public SearchException() {
+ super();
+ }
+
+ public SearchException(final String message) {
+ super(message);
+ }
+}
Added: geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/SearchTerm.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/SearchTerm.java?rev=1900504&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/SearchTerm.java (added)
+++ geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/SearchTerm.java Tue May 3 12:22:08 2022
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package jakarta.mail.search;
+
+import java.io.Serializable;
+
+import jakarta.mail.Message;
+
+/**
+ * Base class for Terms in a parse tree used to represent a search condition.
+ *
+ * This class is Serializable to allow for the short term persistence of
+ * searches between Sessions; this is not intended for long-term persistence.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class SearchTerm implements Serializable {
+
+ private static final long serialVersionUID = -6652358452205992789L;
+
+ /**
+ * Checks a matching criteria defined by the concrete subclass of this Term.
+ *
+ * @param message the message to apply the matching criteria to
+ * @return true if the matching criteria is met
+ */
+ public abstract boolean match(Message message);
+}
Added: geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/SentDateTerm.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/SentDateTerm.java?rev=1900504&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/SentDateTerm.java (added)
+++ geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/SentDateTerm.java Tue May 3 12:22:08 2022
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package jakarta.mail.search;
+
+import java.util.Date;
+
+import jakarta.mail.Message;
+import jakarta.mail.MessagingException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public final class SentDateTerm extends DateTerm {
+
+ private static final long serialVersionUID = 5647755030530907263L;
+
+ public SentDateTerm(final int comparison, final Date date) {
+ super(comparison, date);
+ }
+
+ @Override
+ public boolean match(final Message message) {
+ try {
+ final Date date = message.getSentDate();
+ if (date == null) {
+ return false;
+ }
+
+ return match(message.getSentDate());
+ } catch (final MessagingException e) {
+ return false;
+ }
+ }
+
+ @Override
+ public boolean equals(final Object other) {
+ if (this == other) {
+ return true;
+ }
+ if (other instanceof SentDateTerm == false) {
+ return false;
+ }
+ return super.equals(other);
+ }
+}
Added: geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/SizeTerm.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/SizeTerm.java?rev=1900504&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/SizeTerm.java (added)
+++ geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/SizeTerm.java Tue May 3 12:22:08 2022
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package jakarta.mail.search;
+
+import jakarta.mail.Message;
+import jakarta.mail.MessagingException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public final class SizeTerm extends IntegerComparisonTerm {
+
+ private static final long serialVersionUID = -2556219451005103709L;
+
+ public SizeTerm(final int comparison, final int size) {
+ super(comparison, size);
+ }
+
+ @Override
+ public boolean match(final Message message) {
+ try {
+ return match(message.getSize());
+ } catch (final MessagingException e) {
+ return false;
+ }
+ }
+
+ @Override
+ public boolean equals(final Object other) {
+ if (this == other) {
+ return true;
+ }
+ if (other instanceof SizeTerm == false) {
+ return false;
+ }
+ return super.equals(other);
+ }
+}
Added: geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/StringTerm.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/StringTerm.java?rev=1900504&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/StringTerm.java (added)
+++ geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/StringTerm.java Tue May 3 12:22:08 2022
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package jakarta.mail.search;
+
+/**
+ * A Term that provides matching criteria for Strings.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class StringTerm extends SearchTerm {
+
+ private static final long serialVersionUID = 1274042129007696269L;
+
+ /**
+ * If true, case should be ignored during matching.
+ */
+ protected boolean ignoreCase;
+
+ /**
+ * The pattern associated with this term.
+ */
+ protected String pattern;
+
+ /**
+ * Constructor specifying a pattern.
+ * Defaults to case insensitive matching.
+ * @param pattern the pattern for this term
+ */
+ protected StringTerm(final String pattern) {
+ this(pattern, true);
+ }
+
+ /**
+ * Constructor specifying pattern and case sensitivity.
+ * @param pattern the pattern for this term
+ * @param ignoreCase if true, case should be ignored during matching
+ */
+ protected StringTerm(final String pattern, final boolean ignoreCase) {
+ this.pattern = pattern;
+ this.ignoreCase = ignoreCase;
+ }
+
+ /**
+ * Return the pattern associated with this term.
+ * @return the pattern associated with this term
+ */
+ public String getPattern() {
+ return pattern;
+ }
+
+ /**
+ * Indicate if case should be ignored when matching.
+ * @return if true, case should be ignored during matching
+ */
+ public boolean getIgnoreCase() {
+ return ignoreCase;
+ }
+
+ /**
+ * Determine if the pattern associated with this term is a substring of the
+ * supplied String. If ignoreCase is true then case will be ignored.
+ *
+ * @param match the String to compare to
+ * @return true if this patter is a substring of the supplied String
+ */
+ protected boolean match(final String match) {
+ final int matchLength = pattern.length();
+ final int length = match.length() - matchLength;
+
+ for (int i = 0; i <= length; i++) {
+ if (match.regionMatches(ignoreCase, i, pattern, 0, matchLength)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public boolean equals(final Object other) {
+ if (this == other) {
+ return true;
+ }
+ if (other instanceof StringTerm == false) {
+ return false;
+ }
+
+ final StringTerm term = (StringTerm)other;
+
+ if (ignoreCase) {
+ return term.pattern.equalsIgnoreCase(pattern) && term.ignoreCase == ignoreCase;
+ }
+ else {
+ return term.pattern.equals(pattern) && term.ignoreCase == ignoreCase;
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ return pattern.hashCode() + (ignoreCase ? 32 : 79);
+ }
+}
Added: geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/SubjectTerm.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/SubjectTerm.java?rev=1900504&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/SubjectTerm.java (added)
+++ geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/search/SubjectTerm.java Tue May 3 12:22:08 2022
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package jakarta.mail.search;
+
+import jakarta.mail.Message;
+import jakarta.mail.MessagingException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public final class SubjectTerm extends StringTerm {
+
+ private static final long serialVersionUID = 7481568618055573432L;
+
+ public SubjectTerm(final String subject) {
+ super(subject);
+ }
+
+ @Override
+ public boolean match(final Message message) {
+ try {
+ final String subject = message.getSubject();
+ if (subject == null) {
+ return false;
+ }
+ return match(subject);
+ } catch (final MessagingException e) {
+ return false;
+ }
+ }
+
+ @Override
+ public boolean equals(final Object other) {
+ if (this == other) {
+ return true;
+ }
+ if (other instanceof SubjectTerm == false) {
+ return false;
+ }
+ return super.equals(other);
+ }
+}
Added: geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/util/ByteArrayDataSource.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/util/ByteArrayDataSource.java?rev=1900504&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/util/ByteArrayDataSource.java (added)
+++ geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/util/ByteArrayDataSource.java Tue May 3 12:22:08 2022
@@ -0,0 +1,174 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package jakarta.mail.util;
+
+import jakarta.mail.internet.ContentType;
+import jakarta.mail.internet.MimeUtility;
+import jakarta.mail.internet.ParseException;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import jakarta.activation.DataSource;
+
+
+/**
+ * An activation DataSource object that sources the data from
+ * a byte[] array.
+ * @version $Rev$ $Date$
+ */
+public class ByteArrayDataSource implements DataSource {
+ // the data source
+ private final byte[] source;
+ // the content MIME type
+ private final String contentType;
+ // the name information (defaults to a null string)
+ private String name = "";
+
+
+ /**
+ * Create a ByteArrayDataSource from an input stream.
+ *
+ * @param in The source input stream.
+ * @param type The MIME-type of the data.
+ *
+ * @exception IOException
+ */
+ public ByteArrayDataSource(final InputStream in, final String type) throws IOException {
+ final ByteArrayOutputStream sink = new ByteArrayOutputStream();
+
+ // ok, how I wish you could just pipe an input stream into an output stream :-)
+ final byte[] buffer = new byte[8192];
+ int bytesRead;
+
+ while ((bytesRead = in.read(buffer)) > 0) {
+ sink.write(buffer, 0, bytesRead);
+ }
+
+ source = sink.toByteArray();
+ contentType = type;
+ }
+
+
+ /**
+ * Create a ByteArrayDataSource directly from a byte array.
+ *
+ * @param data The source byte array (not copied).
+ * @param type The content MIME-type.
+ */
+ public ByteArrayDataSource(final byte[] data, final String type) {
+ source = data;
+ contentType = type;
+ }
+
+ /**
+ * Create a ByteArrayDataSource from a string value. If the
+ * type information includes a charset parameter, that charset
+ * is used to extract the bytes. Otherwise, the default Java
+ * char set is used.
+ *
+ * @param data The source data string.
+ * @param type The MIME type information.
+ *
+ * @exception IOException
+ */
+ public ByteArrayDataSource(final String data, final String type) throws IOException {
+ String charset = null;
+ try {
+ // the charset can be encoded in the content type, which we parse using
+ // the ContentType class.
+ final ContentType content = new ContentType(type);
+ charset = content.getParameter("charset");
+ } catch (final ParseException e) {
+ // ignored...just use the default if this fails
+ }
+ if (charset == null) {
+ charset = MimeUtility.getDefaultJavaCharset();
+ }
+ else {
+ // the type information encodes a MIME charset, which may need mapping to a Java one.
+ charset = MimeUtility.javaCharset(charset);
+ }
+
+ // get the source using the specified charset
+ source = data.getBytes(charset);
+ contentType = type;
+ }
+
+
+ /**
+ * Create an input stream for this data. A new input stream
+ * is created each time.
+ *
+ * @return An InputStream for reading the encapsulated data.
+ * @exception IOException
+ */
+ public InputStream getInputStream() throws IOException {
+ return new ByteArrayInputStream(source);
+ }
+
+
+ /**
+ * Open an output stream for the DataSource. This is not
+ * supported by this DataSource, so an IOException is always
+ * throws.
+ *
+ * @return Nothing...an IOException is always thrown.
+ * @exception IOException
+ */
+ public OutputStream getOutputStream() throws IOException {
+ throw new IOException("Writing to a ByteArrayDataSource is not supported");
+ }
+
+
+ /**
+ * Get the MIME content type information for this DataSource.
+ *
+ * @return The MIME content type string.
+ */
+ public String getContentType() {
+ return contentType;
+ }
+
+
+ /**
+ * Retrieve the DataSource name. If not explicitly set, this
+ * returns "".
+ *
+ * @return The currently set DataSource name.
+ */
+ public String getName() {
+ return name;
+ }
+
+
+ /**
+ * Set a new DataSource name.
+ *
+ * @param name The new name.
+ */
+ public void setName(final String name) {
+ this.name = name;
+ }
+}
+
Added: geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/util/SharedByteArrayInputStream.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/util/SharedByteArrayInputStream.java?rev=1900504&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/util/SharedByteArrayInputStream.java (added)
+++ geronimo/specs/trunk/geronimo-jakartamail_2.1_spec/src/main/java/jakarta/mail/util/SharedByteArrayInputStream.java Tue May 3 12:22:08 2022
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package jakarta.mail.util;
+
+import jakarta.mail.internet.SharedInputStream;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+public class SharedByteArrayInputStream extends ByteArrayInputStream implements SharedInputStream {
+
+ /**
+ * Position within shared buffer that this stream starts at.
+ */
+ protected int start;
+
+ /**
+ * Create a SharedByteArrayInputStream that shares the entire
+ * buffer.
+ *
+ * @param buf The input data.
+ */
+ public SharedByteArrayInputStream(final byte[] buf) {
+ this(buf, 0, buf.length);
+ }
+
+
+ /**
+ * Create a SharedByteArrayInputStream using a subset of the
+ * array data.
+ *
+ * @param buf The source data array.
+ * @param offset The starting offset within the array.
+ * @param length The length of data to use.
+ */
+ public SharedByteArrayInputStream(final byte[] buf, final int offset, final int length) {
+ super(buf, offset, length);
+ start = offset;
+ }
+
+
+ /**
+ * Get the position within the output stream, adjusted by the
+ * starting offset.
+ *
+ * @return The adjusted position within the stream.
+ */
+ public long getPosition() {
+ return pos - start;
+ }
+
+
+ /**
+ * Create a new input stream from this input stream, accessing
+ * a subset of the data. Think of it as a substring operation
+ * for a stream.
+ *
+ * The starting offset must be non-negative. The end offset can
+ * by -1, which means use the remainder of the stream.
+ *
+ * @param offset The starting offset.
+ * @param end The end offset (which can be -1).
+ *
+ * @return An InputStream configured to access the indicated data subrange.
+ */
+ public InputStream newStream(final long offset, long end) {
+ if (offset < 0) {
+ throw new IllegalArgumentException("Starting position must be non-negative");
+ }
+ if (end == -1) {
+ end = count - start;
+ }
+ return new SharedByteArrayInputStream(buf, start + (int)offset, (int)(end - offset));
+ }
+}