@@ -0,0 +1,2343 @@
+// Copyright 2022 Google LLC%0A//%0A// Licensed under the Apache License, Version 2.0 (the %22License%22);%0A// you may not use this file except in compliance with the License.%0A// You may obtain a copy of the License at%0A//%0A//     https://www.apache.org/licenses/LICENSE-2.0%0A//%0A// Unless required by applicable law or agreed to in writing, software%0A// distributed under the License is distributed on an %22AS IS%22 BASIS,%0A// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A// See the License for the specific language governing permissions and%0A// limitations under the License.%0A%0A%0A// %5BSTART gmail_create_smime_info%5D%0Aimport com.google.api.services.gmail.model.SmimeInfo;%0Aimport java.io.File;%0Aimport java.io.FileInputStream;%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.util.Base64;%0A%0A/* Class to demonstrate the use of Gmail Create SmimeInfo API */%0Apublic class CreateSmimeInfo %7B%0A    /**%0A     * Create an SmimeInfo resource for a certificate from file.%0A     *%0A     * @param filename Name of the file containing the S/MIME certificate.%0A     * @param password Password for the certificate file, or null if the file is not%0A     *     password-protected.%0A     * @return An SmimeInfo object with the specified certificate.%0A     */%0A    public static SmimeInfo createSmimeInfo(String filename, String password) %7B%0A        SmimeInfo smimeInfo = null;%0A        InputStream in = null;%0A%0A        try %7B%0A            File file = new File(filename);%0A            in = new FileInputStream(file);%0A            byte%5B%5D fileContent = new byte%5B(int) file.length()%5D;%0A            in.read(fileContent);%0A%0A            smimeInfo = new SmimeInfo();%0A            smimeInfo.setPkcs12(Base64.getUrlEncoder().encodeToString(fileContent));%0A            if (password != null && password.length() %3E 0) %7B%0A                smimeInfo.setEncryptedKeyPassword(password);%0A            %7D%0A        %7D catch (Exception e) %7B%0A            System.out.printf(%22An error occured while reading the certificate file: %25s%5Cn%22, e);%0A        %7D finally %7B%0A            try %7B%0A                if (in != null) %7B%0A                    in.close();%0A                %7D%0A            %7D catch (IOException ioe) %7B%0A                System.out.printf(%22An error occured while closing the input stream: %25s%5Cn%22, ioe);%0A            %7D%0A        %7D%0A        return smimeInfo;%0A    %7D%0A%7D%0A// %5BEND gmail_create_smime_info%5D

Create SmimeInfo gmail snippet (#173)