public sealed class OutlookMailClient
Public NotInheritable Class OutlookMailClient
Dim instance As OutlookMailClient
public ref class OutlookMailClient sealed
[<SealedAttribute>]
type OutlookMailClient = class end
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
Imports System.Threading.Tasks
Imports DevCase.ThirdParty.MicrosoftLive
Imports DevCase.ThirdParty.MicrosoftLive
Imports Microsoft.Identity.Client
Imports Microsoft.OData.ProxyExtensions
Imports Microsoft.Office365.OutlookServices
Public NotInheritable Class Form1 : Inherits Form
Private outlookClient As OutlookMailClient
' You can get an API key at Microsoft's Application Registration Portal:
' https://apps.dev.microsoft.com/#/appList
Private ReadOnly clientId As String = "YOUR CLIENT ID"
Private ReadOnly folderName As String = "Youtube"
Private ReadOnly dstFilepath As String = "C:\Youtube Urls.txt"
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.BeginInvoke(Sub() Me.IterateMessages())
End Sub
Private Async Sub IterateMessages()
Me.outlookClient = New OutlookMailClient(Me.clientId, OutlookMailScopes.ReadWrite Or OutlookMailScopes.Send)
Await Me.outlookClient.AuthorizeAsync()
Dim folder As IMailFolder = Await Me.outlookClient.GetFolderAsyncByDisplayName(Me.folderName)
Dim messages As IPagedCollection(Of IMessage) = Await Me.outlookClient.GetMessagesAsync(folder)
Dim pageCount As Integer
Do While True
Debug.WriteLine(String.Format("Reading page {0:00}", Threading.Interlocked.Increment(pageCount)))
For Each msg As IMessage In messages.CurrentPage
Dim success As Boolean = Await Me.ParseAndDeleteYoutubeMessage(msg, Me.dstFilepath)
Next msg
' Read next page of messages.
If messages.MorePagesAvailable Then
messages = Await messages.GetNextPageAsync()
Else
Exit Do
End If
Loop
Debug.WriteLine("Finished!")
End Sub
Private Async Function ParseAndDeleteYoutubeMessage(ByVal msg As IMessage, ByVal dstFile As String) As Task(Of Boolean)
Dim urlRegex As New Regex("content=""http://www.youtube.com.+watch.+uploademail", RegexOptions.IgnoreCase)
Dim attrRegex As New Regex("attribution_link\?a=(.){10,11}&u=\/watch%3Fv%3D", RegexOptions.IgnoreCase)
Try
If (msg.From.EmailAddress.Name.Equals("YouTube", StringComparison.OrdinalIgnoreCase)) Then
Dim body As String = msg.Body.Content
Dim isMatch As Boolean = urlRegex.IsMatch(body)
If Not (isMatch) Then
Throw New InvalidOperationException("Youtube regex doesn't match.")
Else
Dim urlMatches As MatchCollection = urlRegex.Matches(body)
Dim urls As String() =
(From m As Match In urlMatches.Cast(Of Match)
Select (Environment.NewLine & m.Value)
).Distinct().ToArray()
For x As Integer = 0 To (urls.Length - 1)
Dim isAttrMatch As Boolean = attrRegex.IsMatch(urls(x))
If (isAttrMatch) Then
urls(x) = attrRegex.Replace(urls(x), "watch?v=")
End If
urls(x) = urls(x).Replace("content=""", "")
urls(x) = urls(x).Replace("%26feature%3Dem-uploademail", "")
urls(x) = urls(x).Replace("&feature=em-uploademail", "")
urls(x) = urls(x).Replace("%26no_autoplay%3D1", "")
Next x
File.AppendAllText(dstFile, String.Join("", urls))
msg.IsRead = True
Await msg.MoveAsync("DeletedItems")
End If
End If
Return True
Catch ex As Exception
Throw
Return False
End Try
End Function
End Class
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
OutlookMailClient | Initializes a new instance of the OutlookMailClient class. |
Client | Gets the wrapped Outlook services client. |
ClientId | Gets the unique identifier of the registered application to use Outlook.com Mail API. |
IsAuthorized | Gets a value that determines whether Outlook.com API authorization was done. |
Scopes | Gets the current Outlook.com mail OAuthv2 scopes. |
AuthorizeAsync | Authorizes this instance to use Microsoft Outlook Mail services. |
DeleteMessageAsync | Asynchronously permanentlly deletes the specified message. |
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object) |
GetFolderAsyncByDisplayName | Asynchronously gets a mailbox folder that satisfies the specified display name. |
GetFolderAsyncById | Asynchronously gets a mailbox folder that satisfies the specified Id. |
GetFolderAsyncByKnownId | Asynchronously gets a mailbox folder that satisfies the specified known Id. |
GetHashCode | Serves as the default hash function. (Inherited from Object) |
GetMessagesAsync | |
GetType | Gets the Type of the current instance. (Inherited from Object) |
MoveMessageAsync | Asynchronously moves the specified message to the target folder. |
RecycleMessageAsync | Asynchronously sends the specified message to the DeletedItems folder. |
ToString | Returns a string that represents the current object. (Inherited from Object) |
CanConvertTo |
Determines whether the source object can be converted to the specified target type.
(Defined by ObjectExtensions) |
CanConvertToT |
Determines whether the source object can be converted to the specified target type.
(Defined by ObjectExtensions) |
ConvertToT |
Converts an object to the specified target type.
If the conversion fails, an exception is thrown.
(Defined by ObjectExtensions) |
ConvertToT |
Converts an object to the specified target type.
If the conversion fails, returns the specified default value.
(Defined by ObjectExtensions) |
IsDisposable |
Determines whether the specified object is a disposable type
(i.e., it implements IDisposable interface).
(Defined by ObjectExtensions) |
Speak |
Speaks the string representation of the source object by using the
operating system integrated text-to-speech synthesizer.
(Defined by ObjectExtensions) |
Speak |
Speaks the string representation of the source object by using the
operating system integrated text-to-speech synthesizer.
(Defined by ObjectExtensions) |
ThrowIfNullTException |
Throws the specified exception if the source object is null.
(Defined by ObjectExtensions) |