Skip to content

Commit 171de71

Browse files
committed
Initial commit
0 parents  commit 171de71

11 files changed

Lines changed: 1077 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created
2+
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path
3+
4+
name: Maven Package
5+
6+
on: [push]
7+
8+
jobs:
9+
build-central:
10+
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
packages: write
15+
16+
steps:
17+
- uses: actions/checkout@v6
18+
- name: Set up Java for publishing to Maven Central Repository
19+
uses: actions/setup-java@v5
20+
with:
21+
java-version: '17'
22+
distribution: 'temurin'
23+
gpg-passphrase: MAVEN_GPG_PASSPHRASE
24+
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
25+
server-id: central
26+
server-username: MAVEN_USERNAME
27+
server-password: MAVEN_PASSWORD
28+
- name: Publish to the Maven Central Repository
29+
run: mvn -P central --batch-mode deploy
30+
env:
31+
MAVEN_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
32+
MAVEN_PASSWORD: ${{ secrets.MAVEN_CENTRAL_TOKEN }}
33+
34+
build-github:
35+
36+
runs-on: ubuntu-latest
37+
permissions:
38+
contents: read
39+
packages: write
40+
41+
steps:
42+
- uses: actions/checkout@v6
43+
- name: Set up Java for publishing to GitHub Packages
44+
uses: actions/setup-java@v5
45+
with:
46+
java-version: '17'
47+
distribution: 'temurin'
48+
gpg-passphrase: MAVEN_GPG_PASSPHRASE
49+
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
50+
- name: Publish to GitHub Packages
51+
run: mvn -P github --batch-mode deploy
52+
env:
53+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/maven.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
3+
4+
# This workflow uses actions that are not certified by GitHub.
5+
# They are provided by a third-party and are governed by
6+
# separate terms of service, privacy policy, and support
7+
# documentation.
8+
9+
name: Java CI with Maven
10+
11+
on: [push, pull_request]
12+
13+
jobs:
14+
build:
15+
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- uses: actions/checkout@v6
20+
- name: Set up JDK 17
21+
uses: actions/setup-java@v5
22+
with:
23+
java-version: '17'
24+
distribution: 'temurin'
25+
cache: maven
26+
- name: Build with Maven
27+
run: mvn -B package --file pom.xml
28+
29+
# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
30+
- name: Update dependency graph
31+
uses: advanced-security/maven-dependency-submission-action@v5
32+
33+
- name: Upload coverage reports to Codecov
34+
uses: codecov/codecov-action@v6
35+
with:
36+
token: ${{ secrets.CODECOV_TOKEN }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea
2+
target

LICENSE.md

Lines changed: 636 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# yocLib - UTF-7 (Java)
2+
3+
This yocLibrary enables your project to encode and decode UTF-7 in Java.
4+
5+
## Status
6+
7+
![Maven Central Version](https://img.shields.io/maven-central/v/com.yocto/yoclib-utf7)
8+
![Maven Central Snapshot Version](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Fcentral.sonatype.com%2Frepository%2Fmaven-snapshots%2Fcom%2Fyocto%2Fyoclib-utf7%2Fmaven-metadata.xml&label=maven-central-snapshot)
9+
[![Java CI with Maven](https://github.com/yocto/yoclib-utf7-java/actions/workflows/maven.yml/badge.svg)](https://github.com/yocto/yoclib-utf7-java/actions/workflows/maven.yml)
10+
[![codecov](https://codecov.io/gh/yocto/yoclib-utf7-java/graph/badge.svg)](https://codecov.io/gh/yocto/yoclib-utf7-java)
11+
12+
## Installation
13+
14+
```xml
15+
<dependency>
16+
<groupId>com.yocto</groupId>
17+
<artifactId>yoclib-utf7</artifactId>
18+
<version>1.0.0</version>
19+
</dependency>
20+
```
21+
22+
## Use
23+
24+
TODO

pom.xml

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0">
3+
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.yocto</groupId>
7+
<artifactId>yoclib-utf7</artifactId>
8+
<version>1.0.0-SNAPSHOT</version>
9+
10+
<description>This yocLibrary enables your project to encode and decode UTF-7 in Java.</description>
11+
<url>https://yocto.com</url>
12+
13+
<build>
14+
<plugins>
15+
<plugin>
16+
<groupId>org.apache.maven.plugins</groupId>
17+
<artifactId>maven-gpg-plugin</artifactId>
18+
<version>3.2.8</version>
19+
<executions>
20+
<execution>
21+
<id>sign-artifacts</id>
22+
<phase>verify</phase>
23+
<goals>
24+
<goal>sign</goal>
25+
</goals>
26+
</execution>
27+
</executions>
28+
</plugin>
29+
<plugin>
30+
<groupId>org.apache.maven.plugins</groupId>
31+
<artifactId>maven-javadoc-plugin</artifactId>
32+
<version>3.12.0</version>
33+
<executions>
34+
<execution>
35+
<id>attach-javadocs</id>
36+
<goals>
37+
<goal>jar</goal>
38+
</goals>
39+
</execution>
40+
</executions>
41+
</plugin>
42+
<plugin>
43+
<groupId>org.apache.maven.plugins</groupId>
44+
<artifactId>maven-source-plugin</artifactId>
45+
<version>3.4.0</version>
46+
<executions>
47+
<execution>
48+
<id>attach-sources</id>
49+
<goals>
50+
<goal>jar-no-fork</goal>
51+
</goals>
52+
</execution>
53+
</executions>
54+
</plugin>
55+
<plugin>
56+
<groupId>org.jacoco</groupId>
57+
<artifactId>jacoco-maven-plugin</artifactId>
58+
<version>0.8.14</version>
59+
<executions>
60+
<execution>
61+
<id>prepare-agent</id>
62+
<goals>
63+
<goal>prepare-agent</goal>
64+
</goals>
65+
</execution>
66+
<execution>
67+
<id>report</id>
68+
<phase>test</phase>
69+
<goals>
70+
<goal>report</goal>
71+
</goals>
72+
</execution>
73+
</executions>
74+
</plugin>
75+
</plugins>
76+
</build>
77+
78+
<dependencies>
79+
<dependency>
80+
<groupId>org.junit.jupiter</groupId>
81+
<artifactId>junit-jupiter-engine</artifactId>
82+
<version>6.0.3</version>
83+
<scope>test</scope>
84+
</dependency>
85+
</dependencies>
86+
87+
<developers>
88+
<developer>
89+
<id>ben221199</id>
90+
<name>Ben van Hartingsveldt</name>
91+
<email>ben.vanhartingsveldt@yocto.com</email>
92+
<organization>Yocto</organization>
93+
<organizationUrl>https://yocto.com</organizationUrl>
94+
</developer>
95+
</developers>
96+
97+
<licenses>
98+
<license>
99+
<name>GPL-v3.0</name>
100+
<url>http://www.gnu.org/licenses/gpl-3.0.txt</url>
101+
</license>
102+
</licenses>
103+
104+
<profiles>
105+
<profile>
106+
<id>central</id>
107+
<build>
108+
<plugins>
109+
<plugin>
110+
<groupId>org.sonatype.central</groupId>
111+
<artifactId>central-publishing-maven-plugin</artifactId>
112+
<version>0.9.0</version>
113+
<extensions>true</extensions>
114+
<configuration>
115+
<autoPublish>true</autoPublish>
116+
<centralSnapshotsUrl>https://central.sonatype.com/repository/maven-snapshots/</centralSnapshotsUrl>
117+
<publishingServerId>central</publishingServerId>
118+
</configuration>
119+
</plugin>
120+
</plugins>
121+
</build>
122+
</profile>
123+
<profile>
124+
<id>github</id>
125+
<distributionManagement>
126+
<repository>
127+
<id>github</id>
128+
<name>GitHub Packages</name>
129+
<url>https://maven.pkg.github.com/yocto/yoclib-utf7-java</url>
130+
</repository>
131+
</distributionManagement>
132+
</profile>
133+
</profiles>
134+
135+
<properties>
136+
<maven.compiler.source>1.8</maven.compiler.source>
137+
<maven.compiler.target>1.8</maven.compiler.target>
138+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
139+
</properties>
140+
141+
<scm>
142+
<url>https://github.com/yocto/yoclib-utf7-java.git</url>
143+
</scm>
144+
145+
</project>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.yocto.yoclib.utf7;
2+
3+
public class UTF7{
4+
5+
public static String decodeIMAP(String input){
6+
StringBuilder sb = new StringBuilder();
7+
int shiftIndex = -1;
8+
for(int i=0;i<input.length();i++){
9+
char c = input.charAt(i);
10+
if(c==UTF7Constants.SHIFT_IMAP && shiftIndex==-1){
11+
shiftIndex = i;
12+
continue;
13+
}
14+
if(c==UTF7Constants.UNSHIFT && shiftIndex!=-1){
15+
if(shiftIndex+1==i){
16+
sb.append(UTF7Constants.SHIFT_IMAP);
17+
}else{
18+
sb.append(UTF7Helper.decodeIMAPModifiedBase64(input.substring(shiftIndex+1,i)));
19+
}
20+
shiftIndex = -1;
21+
continue;
22+
}
23+
if(shiftIndex==-1){
24+
sb.append(c);
25+
}
26+
}
27+
if(shiftIndex!=-1){
28+
throw new RuntimeException("String terminated in wrong mode.");
29+
}
30+
return sb.toString();
31+
}
32+
33+
public static String encodeIMAP(String input){
34+
StringBuilder sb = new StringBuilder();
35+
char[] chars = input.toCharArray();
36+
for(int i=0;i<chars.length;i++){
37+
char c = chars[i];
38+
if((c>=0x20 && c<=0x25) || (c>=0x27 && c<=0x7E)){
39+
// Printable
40+
sb.append(c);
41+
continue;
42+
}
43+
sb.append(UTF7Constants.SHIFT_IMAP);
44+
if(c!=UTF7Constants.SHIFT_IMAP){
45+
StringBuilder subSB = new StringBuilder();
46+
while(i<chars.length){
47+
c = chars[i];
48+
if((c>=0x20 && c<=0x25) || (c>=0x27 && c<=0x7E) || c==UTF7Constants.SHIFT_IMAP){
49+
i--;
50+
break;
51+
}
52+
i++;
53+
subSB.append(c);
54+
}
55+
56+
sb.append(UTF7Helper.encodeIMAPModifiedBase64(subSB.toString()));
57+
}
58+
sb.append(UTF7Constants.UNSHIFT);
59+
}
60+
return sb.toString();
61+
}
62+
63+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.yocto.yoclib.utf7;
2+
3+
public class UTF7Constants{
4+
5+
public static final char BASE64_SLASH = '/';
6+
public static final char BASE64_SLASH_IMAP = ',';
7+
8+
public static final char[] SET_B = {
9+
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
10+
'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
11+
'0','1','2','3','4','5','6','7','8','9',
12+
'+','/',
13+
};
14+
public static final char[] SET_D = {
15+
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
16+
'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
17+
'0','1','2','3','4','5','6','7','8','9',
18+
'\'','(',')',',','-','.','/',':','?',
19+
};
20+
public static final char[] SET_O = {
21+
'!','"','#','$','%','&','*',';','<','=','>','@','[',']','^','_','`','{','|','}',
22+
};
23+
24+
public static final char SHIFT = '+';
25+
public static final char SHIFT_IMAP = '&';
26+
public static final char UNSHIFT = '-';
27+
28+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.yocto.yoclib.utf7;
2+
3+
import java.nio.charset.StandardCharsets;
4+
import java.util.Base64;
5+
6+
public class UTF7Helper{
7+
8+
private static final Base64.Decoder DECODER = Base64.getMimeDecoder();
9+
private static final Base64.Encoder ENCODER = Base64.getMimeEncoder();
10+
11+
public static String decodeModifiedBase64(String input){
12+
byte[] outputBytes = UTF7Helper.DECODER.decode(input);
13+
return new String(outputBytes,StandardCharsets.UTF_16BE);
14+
}
15+
16+
public static String decodeIMAPModifiedBase64(String input){
17+
return UTF7Helper.decodeModifiedBase64(input.replaceAll(Character.toString(UTF7Constants.BASE64_SLASH_IMAP),Character.toString(UTF7Constants.BASE64_SLASH)));
18+
}
19+
20+
public static String encodeModifiedBase64(String input){
21+
byte[] inputBytes = input.getBytes(StandardCharsets.UTF_16BE);
22+
return UTF7Helper.ENCODER.encodeToString(inputBytes).replaceAll("=","");
23+
}
24+
25+
public static String encodeIMAPModifiedBase64(String input){
26+
return UTF7Helper.encodeModifiedBase64(input).replaceAll(Character.toString(UTF7Constants.BASE64_SLASH),Character.toString(UTF7Constants.BASE64_SLASH_IMAP));
27+
}
28+
29+
}

0 commit comments

Comments
 (0)