X-GM-LABELS | Blog | Limilabs https://www.limilabs.com/blog Using Limilabs .net components Sun, 16 Aug 2015 11:57:05 +0000 en-US hourly 1 https://wordpress.org/?v=6.6.2 Label message with Gmail system label (e.g. Starred) https://www.limilabs.com/blog/label-message-with-gmail-system-label-starred Sat, 31 Mar 2012 07:08:40 +0000 http://www.limilabs.com/blog/?p=2565 If you want to use user-defined label please read label message with user defined label. There are two ways of labeling message with Gmail system label (e.g. Starred) Imap.GmailLabelMessageByUID method GmailLabelMessageByUID method uses Gmail’s X-GM-LABELS extension to the IMAP protocol. You need to provide a folder flag name for it to work correctly e.g. @”\Starred”. […]

The post Label message with Gmail system label (e.g. Starred) first appeared on Blog | Limilabs.

]]>
If you want to use user-defined label please read label message with user defined label.

There are two ways of labeling message with Gmail system label (e.g. Starred)

Imap.GmailLabelMessageByUID method

GmailLabelMessageByUID method uses Gmail’s X-GM-LABELS extension to the IMAP protocol. You need to provide a folder flag name for it to work correctly e.g. @”\Starred”.

You can use FolderFlag class static properties to get common flags:
FolderFlag.XImportant, FolderFlag.XSpam, FolderFlag.XStarred.

// C#

using (Imap imap = new Imap())
{
    imap.ConnectSSL("imap.gmail.com");
    imap.UseBestLogin("pat@gmail.com", "password");

    imap.SelectInbox();
    long last = imap.GetAll().Last();

    imap.GmailLabelMessageByUID(last, FolderFlag.XStarred.Name);

    imap.Close();
}
' VB.NET

Using imap As New Imap()
    imap.ConnectSSL("imap.gmail.com")
    imap.UseBestLogin("pat@gmail.com", "password")

    imap.SelectInbox()
    Dim last As Long = imap.GetAll().Last()

    imap.GmailLabelMessageByUID(last, FolderFlag.XStarred.Name)

    imap.Close()
End Using

Imap.CopyByUID method

The second method basis on the fact that Gmail treats labels as regular IMAP folders.
You just need to know correct folder name and copy the message to this folder.

You can use CommonFolders class to get common folders:

// C#

using (Imap imap = new Imap())
{
    imap.ConnectSSL("imap.gmail.com");
    imap.UseBestLogin("pat@gmail.com", "password");

    List<FolderInfo> folders = imap.GetFolders();

    imap.SelectInbox();
    long last = imap.GetAll().Last();

    imap.CopyByUID(last, new CommonFolders(folders).Flagged);

    imap.Close();
}

' VB.NET

Using imap As New Imap()
    imap.ConnectSSL("imap.gmail.com")
    imap.UseBestLogin("pat@gmail.com", "password")

    Dim folders As List(Of FolderInfo) = imap.GetFolders()

    imap.SelectInbox()
    Dim last As Long = imap.GetAll().Last()

    imap.CopyByUID(last, New CommonFolders(folders).Flagged)

    imap.Close()
End Using

The post Label message with Gmail system label (e.g. Starred) first appeared on Blog | Limilabs.

]]>
List all Gmail labels https://www.limilabs.com/blog/list-all-gmail-labels https://www.limilabs.com/blog/list-all-gmail-labels#comments Fri, 30 Mar 2012 10:32:39 +0000 http://www.limilabs.com/blog/?p=2566 Gmail treats labels as folders for the purposes of IMAP. As such, labels can be modified using the standard IMAP commands, CreateFolder, RenameFolder, and DeleteFolder, that act on folders. System labels, which are labels created by Gmail, are reserved and prefixed by “[Gmail]” or “[GoogleMail]” in the list of labels. // C# using (Imap imap […]

The post List all Gmail labels first appeared on Blog | Limilabs.

]]>
Gmail treats labels as folders for the purposes of IMAP.

As such, labels can be modified using the standard IMAP commands, CreateFolder, RenameFolder, and DeleteFolder, that act on folders.

System labels, which are labels created by Gmail, are reserved and prefixed by “[Gmail]” or “[GoogleMail]” in the list of labels.

// C#

using (Imap imap = new Imap())
{
    imap.ConnectSSL("imap.gmail.com");
    imap.Login("pat@gmail.com", "password");

    List<FolderInfo> folders = imap.GetFolders();
    List<FolderInfo> system = folders.FindAll(x => x.Name.StartsWith("[Gmail]"));
    List<FolderInfo> user = folders.FindAll(x => !x.Name.StartsWith("[Gmail]"));

    Console.WriteLine("System labels:");
    system.ForEach(x => Console.WriteLine(x.Name));
    Console.WriteLine();
    Console.WriteLine("User labels:");
    user.ForEach(x => Console.WriteLine(x.Name));

    imap.Close();
}
' VB.NET

Using imap As New Imap()
    imap.ConnectSSL("imap.gmail.com")
    imap.Login("pat@gmail.com", "password")

    Dim folders As List(Of FolderInfo) = imap.GetFolders()
    Dim system As List(Of FolderInfo) = 
        folders.FindAll(Function(x) x.Name.StartsWith("[Gmail]"))
    Dim user As List(Of FolderInfo) = 
        folders.FindAll(Function(x) Not x.Name.StartsWith("[Gmail]"))

    Console.WriteLine("System labels:")
    system.ForEach(Function(x) Console.WriteLine(x.Name))
    Console.WriteLine()
    Console.WriteLine("User labels:")
    user.ForEach(Function(x) Console.WriteLine(x.Name))

    imap.Close()
End Using

Here is the output:


System labels:
[Gmail]
[Gmail]/All Mail
[Gmail]/Drafts
[Gmail]/Sent Mail
[Gmail]/Spam
[Gmail]/Starred
[Gmail]/Trash


User labels:
Inbox
Personal
Receipts
Travel
Upload
Work
my label
my label/nested
my second label

The post List all Gmail labels first appeared on Blog | Limilabs.

]]>
https://www.limilabs.com/blog/list-all-gmail-labels/feed 2
Gmail extensions in Mail.dll https://www.limilabs.com/blog/gmail-extensions-in-mail-dll https://www.limilabs.com/blog/gmail-extensions-in-mail-dll#comments Mon, 13 Jun 2011 13:05:11 +0000 http://www.limilabs.com/blog/?p=1907 Here’s the list of Gmail IMAP protocol extensions implemented in Mail.dll: Extension of the LIST command: XLIST Extension of the SEARCH command: X-GM-RAW Access to the Gmail unique message ID: X-GM-MSGID Access to the Gmail thread ID: X-GM-THRID Access to Gmail labels: X-GM-LABELS OAuth and OAuth 2.0: XOAUTH, XOAUTH2 You can read on how to […]

The post Gmail extensions in Mail.dll first appeared on Blog | Limilabs.

]]>

Here’s the list of Gmail IMAP protocol extensions implemented in Mail.dll:

  • Extension of the LIST command: XLIST
  • Extension of the SEARCH command: X-GM-RAW
  • Access to the Gmail unique message ID: X-GM-MSGID
  • Access to the Gmail thread ID: X-GM-THRID
  • Access to Gmail labels: X-GM-LABELS
  • OAuth and OAuth 2.0: XOAUTH, XOAUTH2

You can read on how to use Mail.dll with Gmail in the following articles:

OAuth 2.0

OAuth 1.0

The post Gmail extensions in Mail.dll first appeared on Blog | Limilabs.

]]>
https://www.limilabs.com/blog/gmail-extensions-in-mail-dll/feed 1
Search Gmail label https://www.limilabs.com/blog/search-gmail-label https://www.limilabs.com/blog/search-gmail-label#comments Sun, 12 Jun 2011 13:02:27 +0000 http://www.limilabs.com/blog/?p=1896 Gmail treats labels as folders for the purposes of IMAP. As such, labels can be modified using the standard IMAP commands, CreateFolder, RenameFolder, and DeleteFolder, that act on folders. System labels, which are labels created by Gmail, are reserved and prefixed by “[Gmail]” or “[GoogleMail]” in the list of labels. Use the XLIST command to […]

The post Search Gmail label first appeared on Blog | Limilabs.

]]>
Gmail treats labels as folders for the purposes of IMAP.

As such, labels can be modified using the standard IMAP commands, CreateFolder, RenameFolder, and DeleteFolder, that act on folders.

System labels, which are labels created by Gmail, are reserved and prefixed by “[Gmail]” or “[GoogleMail]” in the list of labels.

Use the XLIST command to get the entire list of labels for a mailbox.

The labels for a given message may be retrieved by using the X-GM-LABELS attribute with the FETCH command.

It is also possible to use the X-GM-LABELS attribute to return the UIDs for all messages with a given label, using the SEARCH command.

// C# version

using (Imap imap = new Imap())
{
    imap.ConnectSSL("imap.gmail.com");
    imap.UseBestLogin("pat@gmail.com", "password");

    // Select 'All Mail' folder
    CommonFolders common = new CommonFolders(client.GetFolders());
    client.Select(common.AllMail);

    List<long> uids = imap.Search().Where(
        Expression.GmailLabel("MyLabel"));

    foreach (MessageInfo info in imap.GetMessageInfoByUID(uids))
    {
        Console.WriteLine("{0} - {1}",
            info.Envelope.GmailThreadId,
            info.Envelope.Subject);
    }

    imap.Close();
}

' VB.NET version

Using imap As New Imap()
	imap.ConnectSSL("imap.gmail.com")
	imap.UseBestLogin("pat@gmail.com", "password")

	' Select 'All Mail' folder
	Dim common As New CommonFolders(client.GetFolders())
	client.Select(common.AllMail)

	Dim uids As List(Of Long) = imap.Search().Where(Expression.GmailLabel("MyLabel"))

	For Each info As MessageInfo In imap.GetMessageInfoByUID(uids)
            Console.WriteLine("{0} - {1}",  _
                info.Envelope.GmailThreadId,  _
                info.Envelope.Subject)
	Next

	imap.Close()
End Using

You can learn more about this Gmail IMAP extension here:
http://code.google.com/apis/gmail/imap/#x-gm-labels

The post Search Gmail label first appeared on Blog | Limilabs.

]]>
https://www.limilabs.com/blog/search-gmail-label/feed 1
Label message with Gmail label https://www.limilabs.com/blog/label-message-with-gmail-label https://www.limilabs.com/blog/label-message-with-gmail-label#comments Sun, 12 Jun 2011 13:02:24 +0000 http://www.limilabs.com/blog/?p=1858 If you want to use system label, such as \Starred or \Important please read label message with system label. Gmail treats labels as folders for the purposes of IMAP. As such, labels can be modified using the standard IMAP commands, CreateFolder, RenameFolder, and DeleteFolder, that act on folders. System labels, which are labels created by […]

The post Label message with Gmail label first appeared on Blog | Limilabs.

]]>
If you want to use system label, such as \Starred or \Important please read label message with system label.

Gmail treats labels as folders for the purposes of IMAP.

As such, labels can be modified using the standard IMAP commands, CreateFolder, RenameFolder, and DeleteFolder, that act on folders.

System labels, which are labels created by Gmail, are reserved and prefixed by “[Gmail]” or “[GoogleMail]” in the list of labels.

Use the XLIST command to get the entire list of labels for a mailbox.

The labels for a given message may be retrieved by using the X-GM-LABELS attribute with the FETCH command.

Labels may be added to a message using the STORE command in conjunction with the X-GM-LABELS attribute.

// C# version

using (Imap imap = new Imap())
{
    imap.ConnectSSL("imap.gmail.com");
    imap.UseBestLogin("pat@gmail.com", "password");

    imap.SelectInbox();
    long uid = imap.GetAll().Last();

    imap.GmailLabelMessageByUID(uid, "MyLabel");

    List<string> labels = imap.GmailGetLabelsByUID(uid);
    labels.ForEach(Console.WriteLine);

    imap.Close();
}
' VB.NET version

Using imap As New Imap()
	imap.ConnectSSL("imap.gmail.com")
	imap.UseBestLogin("pat@gmail.com", "password")

	imap.SelectInbox()
	Dim uid As Long = imap.GetAll().Last()

	imap.GmailLabelMessageByUID(uid, "MyLabel")

	Dim labels As List(Of String) = imap.GmailGetLabelsByUID(uid)
	labels.ForEach(Console.WriteLine)

	imap.Close()
End Using

You can learn more about this Gmail IMAP extension here:
http://code.google.com/apis/gmail/imap/#x-gm-labels

The post Label message with Gmail label first appeared on Blog | Limilabs.

]]>
https://www.limilabs.com/blog/label-message-with-gmail-label/feed 1
Get Gmail labels for specified messages https://www.limilabs.com/blog/get-gmail-labels-for-specified-messages https://www.limilabs.com/blog/get-gmail-labels-for-specified-messages#comments Sun, 12 Jun 2011 13:02:22 +0000 http://www.limilabs.com/blog/?p=1857 Gmail treats labels as folders for the purposes of IMAP. As such, labels can be modified using the standard IMAP commands, CreateFolder, RenameFolder, and DeleteFolder, that act on folders. System labels, which are labels created by Gmail, are reserved and prefixed by “[Gmail]” or “[GoogleMail]” in the list of labels. Use the XLIST command to […]

The post Get Gmail labels for specified messages first appeared on Blog | Limilabs.

]]>
Gmail treats labels as folders for the purposes of IMAP.

As such, labels can be modified using the standard IMAP commands, CreateFolder, RenameFolder, and DeleteFolder, that act on folders.

System labels, which are labels created by Gmail, are reserved and prefixed by “[Gmail]” or “[GoogleMail]” in the list of labels.

Use the XLIST command to get the entire list of labels for a mailbox.

The labels for a given message may be retrieved by using the X-GM-LABELS attribute with the FETCH command.

For list of messages

// C# version

using (Imap imap = new Imap())
{
    imap.ConnectSSL("imap.gmail.com");
    imap.UseBestLogin("pat@gmail.com", "password");

    imap.SelectInbox();

    List<long> uids = imap.GetAll();
    List<messageInfo> infos = imap.GetMessageInfoByUID(uids);

    foreach (MessageInfo info in infos)
    {
        List<string> labels = info.GmailLabels.Labels;

        Console.WriteLine("[{0}] {1}",
            string.Join(" ", labels.ToArray()),
            info.Envelope.Subject);
    }

    imap.Close();
}
' VB.NET version

Using imap As New Imap()
	imap.ConnectSSL("imap.gmail.com")
	imap.UseBestLogin("pat@gmail.com", "password")

	imap.SelectInbox()

	Dim uids As List(Of Long) = imap.GetAll()
	Dim infos As List(Of MessageInfo) = imap.GetMessageInfoByUID(uids)

	For Each info As MessageInfo In infos
            Dim labels As List(Of String) = info.GmailLabels.Labels

	    Console.WriteLine("[{0}] {1}",  _
                String.Join(" ", labels.ToArray()),  _
                info.Envelope.Subject)
	Next

	imap.Close()
End Using

For single message:

// C# version

using (Imap imap = new Imap())
{
    imap.ConnectSSL("imap.gmail.com");
    imap.Login("pat@gmail.com", "password");

    imap.SelectInbox();

    long uid = imap.GetAll().Last();
    List<string> labels = imap.GmailGetLabelsByUID(uid);

    labels.ForEach(Console.WriteLine);

    imap.Close();
}
' VB.NET version

Using imap As New Imap()
	imap.ConnectSSL("imap.gmail.com")
	imap.Login("pat@gmail.com", "password")

	imap.SelectInbox()

	Dim uid As Long = imap.GetAll().Last()
	Dim labels As List(Of String) = imap.GmailGetLabelsByUID(uid)

	labels.ForEach(Console.WriteLine)

	imap.Close()
End Using

You can learn more about this Gmail IMAP extension here:
http://code.google.com/apis/gmail/imap/#x-gm-labels

The post Get Gmail labels for specified messages first appeared on Blog | Limilabs.

]]>
https://www.limilabs.com/blog/get-gmail-labels-for-specified-messages/feed 1