diff --git a/googlearcdl.sln b/googlearcdl.sln new file mode 100644 index 0000000..4c55796 --- /dev/null +++ b/googlearcdl.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29806.167 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "googlearcdl", "googlearcdl\googlearcdl.csproj", "{AE714D7C-7FFC-4A04-8DFB-AB5500EAD843}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AE714D7C-7FFC-4A04-8DFB-AB5500EAD843}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AE714D7C-7FFC-4A04-8DFB-AB5500EAD843}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AE714D7C-7FFC-4A04-8DFB-AB5500EAD843}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AE714D7C-7FFC-4A04-8DFB-AB5500EAD843}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {0CD0E430-7541-4FA3-B3E1-824FD75327E7} + EndGlobalSection +EndGlobal diff --git a/googlearcdl/App.config b/googlearcdl/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/googlearcdl/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/googlearcdl/Program.cs b/googlearcdl/Program.cs new file mode 100644 index 0000000..a88675c --- /dev/null +++ b/googlearcdl/Program.cs @@ -0,0 +1,77 @@ +using System; +using System.IO; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +using Microsoft.Owin.Security.DataHandler.Encoder; +using MailKit; + +using Google.Apis.Auth.OAuth2; +using Google.Apis.Gmail.v1; +using Google.Apis.Gmail.v1.Data; +using Google.Apis.Services; +using Google.Apis.Util.Store; + +namespace googlearcdl +{ + class Program + { + static string[] Scopes = { GmailService.Scope.GmailReadonly }; + static string ApplicationName = "Gmail API .NET Quickstart"; + + static void Main(string[] args) + { + UserCredential credential; + + using (var stream = + new FileStream("client_id.json", FileMode.Open, FileAccess.Read)) + { + // The file token.json stores the user's access and refresh tokens, and is created + // automatically when the authorization flow completes for the first time. + string credPath = "token.json"; + credential = GoogleWebAuthorizationBroker.AuthorizeAsync( + GoogleClientSecrets.Load(stream).Secrets, + Scopes, + "user", + CancellationToken.None, + new FileDataStore(credPath, true)).Result; + Console.WriteLine("Credential file saved to: " + credPath); + } + + // Create Gmail API service. + var service = new GmailService(new BaseClientService.Initializer() + { + HttpClientInitializer = credential, + ApplicationName = ApplicationName, + }); + + var queryRequest = service.Users.Messages.List("me"); + queryRequest.Q = "Google のデータ アーカイブをご利用いただけるようになりました"; + do + { + var queryResult = queryRequest.Execute(); + foreach (var message in queryResult.Messages) + { + var messageRequest = service.Users.Messages.Get("me", message.Id); + messageRequest.Format = UsersResource.MessagesResource.GetRequest.FormatEnum.Raw; + var messageResult = messageRequest.Execute(); + + var encoder = new Base64UrlTextEncoder(); + var stream = new MemoryStream(encoder.Decode(messageResult.Raw)); + + var mail = MimeKit.MimeMessage.Load(stream); + + Console.WriteLine("{0}", mail.Subject); + } + + queryRequest.PageToken = queryResult.NextPageToken; + + } while (!String.IsNullOrEmpty(queryRequest.PageToken)); + + Console.Read(); + } + } +} diff --git a/googlearcdl/Properties/AssemblyInfo.cs b/googlearcdl/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..2ad592e --- /dev/null +++ b/googlearcdl/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// アセンブリに関する一般情報は以下の属性セットをとおして制御されます。 +// 制御されます。アセンブリに関連付けられている情報を変更するには、 +// これらの属性値を変更します。 +[assembly: AssemblyTitle("googlearcdl")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("googlearcdl")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible を false に設定すると、このアセンブリ内の型は COM コンポーネントから +// 参照できなくなります。COM からこのアセンブリ内の型にアクセスする必要がある場合は、 +// その型の ComVisible 属性を true に設定します。 +[assembly: ComVisible(false)] + +// このプロジェクトが COM に公開される場合、次の GUID が typelib の ID になります +[assembly: Guid("ae714d7c-7ffc-4a04-8dfb-ab5500ead843")] + +// アセンブリのバージョン情報は次の 4 つの値で構成されています: +// +// メジャー バージョン +// マイナー バージョン +// ビルド番号 +// リビジョン +// +// すべての値を指定するか、次を使用してビルド番号とリビジョン番号を既定に設定できます +// 既定値にすることができます: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/googlearcdl/googlearcdl.csproj b/googlearcdl/googlearcdl.csproj new file mode 100644 index 0000000..b12f8dd --- /dev/null +++ b/googlearcdl/googlearcdl.csproj @@ -0,0 +1,94 @@ + + + + + Debug + AnyCPU + {AE714D7C-7FFC-4A04-8DFB-AB5500EAD843} + Exe + googlearcdl + googlearcdl + v4.7.2 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\BouncyCastle.1.8.5\lib\BouncyCastle.Crypto.dll + + + ..\packages\Google.Apis.1.44.0\lib\net45\Google.Apis.dll + + + ..\packages\Google.Apis.Auth.1.44.0\lib\net45\Google.Apis.Auth.dll + + + ..\packages\Google.Apis.Auth.1.44.0\lib\net45\Google.Apis.Auth.PlatformServices.dll + + + ..\packages\Google.Apis.Core.1.44.0\lib\net45\Google.Apis.Core.dll + + + ..\packages\Google.Apis.Gmail.v1.1.44.0.1859\lib\net45\Google.Apis.Gmail.v1.dll + + + ..\packages\Google.Apis.1.44.0\lib\net45\Google.Apis.PlatformServices.dll + + + ..\packages\MailKit.2.5.1\lib\net47\MailKit.dll + + + ..\packages\Microsoft.Owin.4.1.0\lib\net45\Microsoft.Owin.dll + + + ..\packages\Microsoft.Owin.Security.4.1.0\lib\net45\Microsoft.Owin.Security.dll + + + ..\packages\MimeKit.2.5.1\lib\net47\MimeKit.dll + + + ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll + + + ..\packages\Owin.1.0\lib\net40\Owin.dll + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/googlearcdl/packages.config b/googlearcdl/packages.config new file mode 100644 index 0000000..7139100 --- /dev/null +++ b/googlearcdl/packages.config @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file