<?xml version='1.0' standalone='yes'?>
<container
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:var="http://www.skyrix.com/od/binding"
    xmlns:label="OGo:label">
    
  <div class="view-list hide-print" layout="column" ng-class="{'view-list--close': mailbox.centerIsClose(centerIsClose)}">
     <!-- in virtual mailbox mode -->
    <md-toolbar class="md-whiteframe-z1 md-hue-2 _md _md-toolbar-transitions advanced-search-clickable-toolbar"
                ng-hide="app.service.$virtualPath === false || mailbox.mode.multiple"
                ng-click="app.showAdvancedSearch()">
      <md-icon class="material-icons sg-icon-toolbar-bg">search</md-icon>
      <div class="sg-toolbar-auto">
       <form class="md-toolbar-tools sg-toolbar-secondary" layout="row">
          <div ng-click="app.hideAdvancedSearch($event)">
            <a class="sg-icon-button" ng-click="app.hideAdvancedSearch($event)" aria-label="Back">
              <md-icon>arrow_back</md-icon>
            </a>
          </div>
          <md-input-container class="md-flex" md-no-float="md-no-float">
            <var:string label:value="Advanced search"/>
          </md-input-container>
          
          <a class="sg-icon-button show-advanced-search" ng-click="app.showAdvancedSearch()" aria-label="Advanced search">
            <md-icon>more_horiz</md-icon>
            <md-tooltip><var:string label:value="Advanced search"/></md-tooltip>
          </a>
        </form>
      </div>
    </md-toolbar>
    <!-- single-selection toolbars -->
    <md-toolbar class="md-accent md-hue-1"
              ng-hide="mailbox.service.$virtualPath !== false || mailbox.mode.multiple">
      <!-- sort mode (default) -->
      <div class="md-toolbar-tools" ng-hide="mailbox.mode.search">
        <md-button class="sg-icon-button" label:aria-label="Search"
                   ng-click="mailbox.searchMode()">
          <md-icon>search</md-icon>
        </md-button>
        <a href="#" class="sg-folder-name"
           ng-click="mailbox.searchMode($event)" ng-bind="mailbox.service.selectedFolder.$displayName"><!-- mailbox name --></a>
        <md-menu>
          <md-button class="sg-icon-button" label:aria-label="Filter"
                     ng-click="$mdMenu.open()">
            <md-tooltip md-direction="bottom"><var:string label:value="Filter"/></md-tooltip>
            <md-icon>filter_list</md-icon>
          </md-button>
          <md-menu-content width="4">
            <md-menu-item>
              <sg-checkmark
                  ng-change="mailbox.selectedFolder.$filter(mailbox.service.$query)"
                  ng-model="mailbox.selectedFolder.$unseenOnly"
                  sg-true-value="1"
                  sg-false-value="0"> <var:string label:value="Show unread messages only"/></sg-checkmark>
            </md-menu-item>
            <md-menu-item>
              <sg-checkmark
                  ng-change="mailbox.selectedFolder.$filter(mailbox.service.$query)"
                  ng-model="mailbox.selectedFolder.$flaggedOnly"
                  sg-true-value="1"
                  sg-false-value="0"> <var:string label:value="Show flagged messages only"/></sg-checkmark>
            </md-menu-item>
            <md-menu-divider> <!-- divider --></md-menu-divider>
            <md-menu-item ng-repeat="label in mailbox.selectedFolder.$labels track by label.imapName">
              <sg-checkmark
                  ng-change="mailbox.selectedFolder.$filter(mailbox.service.$query)"
                  ng-model="mailbox.selectedFolder.$filteredLabels[label.imapName]"
                  sg-true-value="1"
                  sg-false-value="0">
                <div layout="row" layout-align="start center">
                  <div class="sg-color-chip"
                       ng-style="{ backgroundColor: label.color || '#333' }"><!-- color --></div>
                  {{ label.name || label.imapName }}
                </div>
              </sg-checkmark>
            </md-menu-item>
          </md-menu-content>
        </md-menu>
        <md-menu>
          <md-button class="sg-icon-button" label:aria-label="Sort" ng-click="$mdMenu.open()">
            <md-tooltip md-direction="bottom"><var:string label:value="Sort"/></md-tooltip>
            <md-icon>sort</md-icon>
          </md-button>
          <md-menu-content>
            <md-menu-item>
              <md-button ng-click="mailbox.sort('subject')">
                <md-icon label:aria-label="Subject">{{ mailbox.sortedBy('subject') ? 'check' : null }}</md-icon> <var:string label:value="Subject"/>
              </md-button>
            </md-menu-item>
            <md-menu-item ng-if="!mailbox.selectedFolder.isSentFolder">
              <md-button ng-click="mailbox.sort('from')">
                <md-icon label:aria-label="From">{{ mailbox.sortedBy('from') ? 'check' : null }}</md-icon> <var:string label:value="From"/>
              </md-button>
            </md-menu-item>
            <md-menu-item ng-if="mailbox.selectedFolder.isSentFolder">
              <md-button ng-click="mailbox.sort('to')">
                <md-icon label:aria-label="To">{{ mailbox.sortedBy('to') ? 'check' : null }}</md-icon> <var:string label:value="To"/>
              </md-button>
            </md-menu-item>
            <md-menu-item>
              <md-button ng-click="mailbox.sort('date')">
                <md-icon label:aria-label="Date">{{ mailbox.sortedBy('date') ? 'check' : null }}</md-icon> <var:string label:value="Date"/>
              </md-button>
            </md-menu-item>
            <md-menu-item>
              <md-button ng-click="mailbox.sort('size')">
                <md-icon label:aria-label="Size">{{ mailbox.sortedBy('size') ? 'check' : null }}</md-icon> <var:string label:value="Size"/>
              </md-button>
            </md-menu-item>
	          <md-menu-item>
              <md-button ng-click="mailbox.sort('arrival')">
                <md-icon label:aria-label="Order Received">{{ mailbox.sortedBy('arrival') ? 'check' : null }}</md-icon> <var:string label:value="Order Received"/>
              </md-button>
            </md-menu-item>
            <md-menu-divider> <!-- divider --></md-menu-divider>
            <md-menu-item>
              <sg-checkmark
                  label:aria-label="Descending Order"
                  ng-model="mailbox.service.$query.asc"
                  ng-change="mailbox.selectedFolder.$filter(mailbox.service.$query)"
                  sg-true-value="0"
                  sg-false-value="1"><var:string label:value="Descending Order"/></sg-checkmark>
            </md-menu-item>
          </md-menu-content>
        </md-menu>
        <md-button class="sg-icon-button" label:aria-label="Get Mail" ng-click="mailbox.refresh()" >
          <md-tooltip md-direction="bottom"><var:string label:value="Refresh"/></md-tooltip>
          <md-icon>refresh</md-icon>
        </md-button>
      </div>
      <!-- search mode -->
      <form class="md-toolbar-tools sg-toolbar-secondary"
            name="searchForm"
            layout="row"
            ng-show="mailbox.mode.search"
            sg-search="mailbox.selectedFolder.$filter(null, [{ searchBy: searchField, searchInput: searchText }])"
            sg-allow-dot="false">
        <md-button class="sg-icon-button"
                   sg-search-cancel="mailbox.cancelSearch()"
                   label:aria-label="Back">
          <md-icon>arrow_back</md-icon>
        </md-button>
        <md-input-container class="md-flex" md-no-float="md-no-float">
          <input name="folderSearch" type="search" var:minlength="minimumSearchLength" label:placeholder="Search" sg-focus-on="search" />
          <div ng-messages="searchForm.folderSearch.$error" ng-show="searchForm.folderSearch.$dirty">
            <div ng-message="minlength"><var:string value="minimumSearchLengthLabel"/></div>
          </div>
        </md-input-container>
        <md-input-container flex="25">
          <md-select label:aria-label="Search scope">
            <md-option value="subject_or_from" selected="selected" ng-if="!mailbox.selectedFolder.isSentFolder"><var:string label:value="Subject or Sender"/></md-option>
            <md-option value="subject_or_to" selected="selected" ng-if="mailbox.selectedFolder.isSentFolder"><var:string label:value="Subject or Recipient"/></md-option>
            <md-option value="subject"><var:string label:value="Subject"/></md-option>
            <md-option value="from"><var:string label:value="Sender"/></md-option>
            <md-option value="to_or_cc"><var:string label:value="To or Cc"/></md-option>
            <md-option value="body"><var:string label:value="Entire Message"/></md-option>
          </md-select>
        </md-input-container>
        <a class="sg-icon-button show-advanced-search" ng-click="app.showAdvancedSearch()" aria-label="Advanced search">
          <md-icon>more_horiz</md-icon>
          <md-tooltip><var:string label:value="Advanced search"/></md-tooltip>
        </a>
      </form>
    </md-toolbar>

    <!-- multiple-selection mode -->
    <md-toolbar class="md-hue-1 sg-toolbar-secondary"
                ng-show="mailbox.mode.multiple">
      <div class="md-toolbar-tools">
        <md-button class="sg-icon-button" ng-click="mailbox.unselectMessages()">
          <md-icon>arrow_back</md-icon>
        </md-button>
        <label class="md-truncate"><span ng-bind="mailbox.service.selectedFolder.selectedCount()"><!-- count --></span> <var:string label:value="selected"/></label>
        <div class="md-flex"><!-- spacer --></div>
        <md-button class="sg-icon-button" ng-click="mailbox.selectAll()">
          <md-tooltip md-direction="bottom"><var:string label:value="Select All"/></md-tooltip>
          <md-icon>select_all</md-icon>
        </md-button>
        <md-button class="sg-icon-button" ng-click="mailbox.confirmDeleteSelectedMessages($event)">
          <md-tooltip md-direction="bottom"><var:string label:value="Delete selected message or folder"/></md-tooltip>
          <md-icon>delete</md-icon>
        </md-button>
        <md-button class="sg-icon-button" ng-click="mailbox.markOrUnMarkMessagesAsJunk()">
          <md-icon ng-hide="::mailbox.service.selectedFolder.type == 'junk'">thumb_down</md-icon>
	  <md-tooltip ng-hide="::mailbox.service.selectedFolder.type == 'junk'" md-direction="bottom"><var:string label:value="Junk"/></md-tooltip>	
          <md-icon ng-hide="::mailbox.service.selectedFolder.type != 'junk'">thumb_up</md-icon>
	  <md-tooltip ng-hide="::mailbox.service.selectedFolder.type != 'junk'" md-direction="bottom"><var:string label:value="Not junk"/></md-tooltip>
        </md-button>
        <md-menu>
          <md-button class="sg-icon-button" label:aria-label="More messages options" ng-click="$mdMenu.open()">
            <md-icon>more_vert</md-icon>
          </md-button>
          <md-menu-content width="2">
            <md-menu-item>
              <md-button ng-click="mailbox.markSelectedMessagesAsFlagged()">
                <var:string label:value="Flag"/>
              </md-button>
            </md-menu-item>
            <md-menu-item>
              <md-button ng-click="mailbox.markSelectedMessagesAsUnread()">
                <var:string label:value="Mark as Unread"/>
              </md-button>
            </md-menu-item>
            <md-menu-item>
              <md-button ng-click="mailbox.markSelectedMessagesAsRead()">
                <var:string label:value="Mark as Read"/>
              </md-button>
            </md-menu-item>
            <md-menu-item>
              <md-button ng-click="mailbox.forwardSelectedMessages($event)">
                <var:string label:value="Forward"/>
              </md-button>
            </md-menu-item>
            <md-menu-item>
              <md-button ng-click="mailbox.selectedFolder.saveSelectedMessages()">
                <var:string label:value="Save As..."/>
              </md-button>
            </md-menu-item>
            <md-menu-item>
              <md-menu>
                <md-button label:aria-label="Copy To" ng-click="$mdMenu.open($event)">
                  <var:string label:value="Copy To"/>
                </md-button>
                <md-menu-content width="4">
                  <div ng-repeat="account in ::mailbox.accounts track by account.id">
                    <md-menu-item>
                      <md-menu>
                        <md-button class="md-primary"
                                   aria-label="{{ ::account.name }}"
                                   ng-click="$mdMenu.open($event)"
                                   ng-bind="::account.name"><!-- account name --></md-button>
                        <md-menu-content class="md-dense" width="4">
                          <div ng-repeat="folder in
                                          account.$flattenMailboxes({ all: true })
                                          track by folder.path">
                            <md-menu-item>
                              <md-button class="sg-no-wrap"
                                         aria-label="{{folder.$displayName}}"
                                         ng-disabled="::(mailbox.service.selectedFolder.id == folder.id)"
                                         ng-click="mailbox.copySelectedMessages(folder.id)">
                                <span ng-class="::('sg-child-level-' + folder.level)"
                                      ng-bind="folder.$displayName"><!-- mailbox name --></span>
                              </md-button>
                            </md-menu-item>
                          </div>
                        </md-menu-content>
                      </md-menu>
                    </md-menu-item>
                  </div>
                </md-menu-content>
              </md-menu>
            </md-menu-item>
            <md-menu-item>
              <md-menu>
                <md-button label:aria-label="Move To" ng-click="$mdMenu.open($event)">
                  <var:string label:value="Move To"/>
                </md-button>
                <md-menu-content width="4">
                  <div ng-repeat="account in ::mailbox.accounts track by account.id">
                    <md-menu-item>
                      <md-menu>
                        <md-button class="md-primary"
                                   aria-label="{{ ::account.name }}"
                                   ng-click="$mdMenu.open($event)"
                                   ng-bind="::account.name"><!-- account name --></md-button>
                        <md-menu-content class="md-dense" width="4">
                          <div ng-repeat="folder in
                                          account.$flattenMailboxes({ all: true })
                                          track by folder.path">
                            <md-menu-item>
                              <md-button class="sg-no-wrap"
                                         aria-label="{{folder.$displayName}}"
                                         ng-disabled="::(mailbox.service.selectedFolder.id == folder.id)"
                                         ng-click="mailbox.moveSelectedMessages(folder.id, null)">
                                <span ng-class="::('sg-child-level-' + folder.level)"
                                      ng-bind="folder.$displayName"><!-- mailbox name --></span>
                              </md-button>
                            </md-menu-item>
                          </div>
                        </md-menu-content>
                      </md-menu>
                    </md-menu-item>
                  </div>
                </md-menu-content>
              </md-menu>
            </md-menu-item>
          </md-menu-content>
        </md-menu>
      </div>
    </md-toolbar>

    <md-divider><!-- divider --></md-divider>

    <md-content id="messagesList" layout="column" class="md-flex">
      <md-subheader>
        <div layout="row"  layout-align="space-between center">
          <div class="md-truncate" ng-switch="mailbox.service.selectedFolder.getLength()">
            <!-- message count -->
            <span ng-switch-when="0"><var:string label:value="No message"/></span>
            <span ng-switch-default="true"><span ng-bind="mailbox.service.selectedFolder.getLength()"><!-- count --></span> <var:string label:value="messages"/></span>
          </div>
          <div class="md-truncate">
            <md-icon label:aria-label="Filtered by label" ng-show="mailbox.selectedFolder.filteredByLabel()">label_outline</md-icon>
            <span ng-show="mailbox.selectedFolder.$unseenOnly"><var:string label:value="Unread"/></span>
            <span ng-show="mailbox.selectedFolder.$flaggedOnly"><var:string label:value="Flagged"/></span>
            <md-icon ng-class="{ 'md-flip': mailbox.ascending() }">sort</md-icon>
            <span ng-bind="mailbox.sort() | loc"><!-- active sort --></span>
          </div>
        </div>
      </md-subheader>
      <md-virtual-repeat-container class="md-flex" md-top-index="mailbox.selectedFolder.$topIndex">
        <md-list class="sg-section-list"
                 ng-class="{ 'sg-list-selectable': mailbox.mode.multiple }"
                 sg-draggable="mailbox.selectedFolder"
                 sg-drag-start="mailbox.selectedFolder.hasSelectedMessage() || mailbox.selectedFolder.selectedCount()"
                 sg-drag-count="mailbox.selectedFolder.selectedCount()">
          <md-list-item
              aria-label="{{currentMessage.subject}}"
              class="sg-message-list-item"
              ng-class="{'md-default-theme md-accent md-bg md-hue-2': mailbox.selectedFolder.isSelectedMessage(currentMessage.uid, currentMessage.$mailbox.path), 'sg-star-bg': currentMessage.isflagged, 'sg-message-thread-first': currentMessage.first, 'sg-message-thread': currentMessage.threadMember}"
              md-virtual-repeat="currentMessage in mailbox.service.selectedFolder"
              md-on-demand="md-on-demand" md-item-size="56"
              ng-click="mailbox.selectMessage(currentMessage)"
              sg-message="currentMessage">
            <div class="md-secondary sg-avatar-selectable"
                 label:aria-label="Select Message"
                 ng-class="{ 'sg-avatar-selected': currentMessage.selected }"
                 ng-click="mailbox.toggleMessageSelection($event, currentMessage)">
              <sg-avatar-image
                  sg-email="mailbox.service.selectedFolder.type == 'sent' ? currentMessage.to[0].email : currentMessage.from[0].email"
                  size="40">person</sg-avatar-image>
            </div>
            <div class="md-list-item-inner sg-message-list-item-main">
              <!-- sgMessageListItemMain directive -->
            </div>
          </md-list-item>
        </md-list>
      </md-virtual-repeat-container>
      <div class="sg-progress-circular-floating"
           ng-show="mailbox.service.selectedFolder.$isLoading">
        <md-progress-circular class="md-accent"
                              md-mode="indeterminate"
                              md-diameter="32"><!-- mailbox loading progress --></md-progress-circular>
      </div>
    </md-content>
  </div>

  <md-fab-speed-dial
      class="md-scale sg-fab-bottom-center"
      ng-if="::!mailbox.composeWindowEnabled()"
      ng-show="!mailbox.selectedFolder.hasSelectedMessage() || isGtExtraSmall"
      ng-cloak="ng-cloak"
      ng-class="{ 'sg-sidenav-close': leftIsClose, 'sg-center-close': mailbox.centerIsClose(centerIsClose) }"
      md-direction="up">
    <md-fab-trigger>
      <md-button class="md-fab md-accent" label:aria-label="Write a new message">
        <md-icon>edit</md-icon>
      </md-button>
    </md-fab-trigger>
    <md-fab-actions>
      <md-button class="md-fab md-raised md-mini" var:aria-label="Write a new message"
                 ng-click="mailbox.newMessage($event)">
        <md-tooltip md-direction="left"><var:string label:value="Write a new message"/></md-tooltip>
        <md-icon>open_in_browser</md-icon>
      </md-button>
      <md-button class="md-fab md-raised md-mini" var:aria-label="Write a message in new window"
                 ng-click="mailbox.newMessage($event, true)">
        <md-tooltip md-direction="left"><var:string label:value="Write a message in new window"/></md-tooltip>
        <md-icon>open_in_new</md-icon>
      </md-button>
    </md-fab-actions>
  </md-fab-speed-dial>

  <md-button
      class="md-fab md-accent sg-fab-bottom-center"
      var:aria-label="Write a new message"
      ng-if="::mailbox.composeWindowEnabled()"
      ng-show="!mailbox.selectedFolder.hasSelectedMessage() || isGtExtraSmall"
      ng-class="{ 'sg-sidenav-close': leftIsClose, 'sg-center-close': mailbox.centerIsClose(centerIsClose) }"
      ng-click="mailbox.newMessage($event)">
    <md-tooltip md-direction="left"><var:string label:value="Write a new message"/></md-tooltip>
    <md-icon>edit</md-icon>
  </md-button>

  <div id="detailView" class="view-detail sg-block-print"
       layout="column" layout-align="start center"
       ng-class="{ 'sg-close': !mailbox.service.selectedFolder.hasSelectedMessage() }"
       md-colors="::{backgroundColor: 'default-background-200'}"
       ui-view="message">
    <md-content class="hide show-gt-md md-flex"
                md-colors="::{backgroundColor: 'default-background-200'}"
                layout="column" layout-align="center center" layout-fill="layout-fill">
      <div class="sg-md-title"
           md-colors="::{color: 'default-background-500'}"><var:string label:value="No message selected"/></div>
    </md-content>
  </div>
  <script type="text/ng-template" id="advancedSearch">
    <md-dialog flex="50" flex-sm="80" flex-xs="100">
      <md-toolbar>
        <div class="md-toolbar-tools">
          <md-icon class="material-icons sg-icon-toolbar-bg">search</md-icon>
          <div class="pseudo-input-container md-flex">
            <var:string label:value="Advanced search"/>
          </div>
          <md-button class="md-icon-button" ng-click="dialogCtrl.closeDialog()">
            <md-icon aria-label="Close dialog">close</md-icon>
          </md-button>
        </div>
      </md-toolbar>
      <md-dialog-content class="md-dialog-content">

          <div class="md-toolbar-tools sg-toolbar-auto advanced-search">

            <md-input-container class="advanced-search-full">
                <label><var:string label:value="From"/></label>
                <input type="text" var:value="dialogCtrl.mainController.searchForm.from" ng-model="dialogCtrl.mainController.searchForm.from" ng-keyup="dialogCtrl.mainController.searchFieldChange($event)" />
              </md-input-container>

              <md-input-container class="advanced-search-full">
                <label><var:string label:value="To"/></label>
                <input type="text" var:value="dialogCtrl.mainController.searchForm.to"  ng-model="dialogCtrl.mainController.searchForm.to" ng-keyup="dialogCtrl.mainController.searchFieldChange($event)"/>
              </md-input-container>

              <md-input-container class="advanced-search-full">
                <label><var:string label:value="Contains"/></label>
                <input type="text" var:value="dialogCtrl.mainController.searchForm.contains" ng-model="dialogCtrl.mainController.searchForm.contains" ng-keyup="dialogCtrl.mainController.searchFieldChange($event)" />
              </md-input-container>

              <md-input-container class="advanced-search-full">
                <label><var:string label:value="Does not contains"/></label>
                <input type="text" var:value="dialogCtrl.mainController.searchForm.doesnotcontains" ng-model="dialogCtrl.mainController.searchForm.doesnotcontains" ng-keyup="dialogCtrl.mainController.searchFieldChange($event)"/>
              </md-input-container>

              <md-input-container class="advanced-search-full">
                <label><var:string label:value="Subject"/></label>
                <input type="text" var:value="dialogCtrl.mainController.searchForm.subject" ng-model="dialogCtrl.mainController.searchForm.subject" ng-keyup="dialogCtrl.mainController.searchFieldChange($event)"/>
              </md-input-container>

              <md-input-container class="advanced-search-full">
                <label><var:string label:value="Body"/></label>
                <input type="text" var:value="dialogCtrl.mainController.searchForm.body" ng-model="dialogCtrl.mainController.searchForm.body" ng-keyup="dialogCtrl.mainController.searchFieldChange($event)"/>
              </md-input-container>

              <div class="search-inline">
                <md-select ng-model="dialogCtrl.mainController.searchForm.date"  class="search-right-space">
                    <md-option value="anytime">
                      <var:string label:value="Anytime"/>
                    </md-option>
                    <md-option value="last7days">
                      <var:string label:value="Last 7 days"/>
                    </md-option>
                    <md-option value="last30days">
                      <var:string label:value="Last 30 days"/>
                    </md-option>
                    <md-option value="last6month">
                      <var:string label:value="Last 6 month"/>
                    </md-option>
                    <md-option value="before">
                      <var:string label:value="Before"/>
                    </md-option>
                    <md-option value="after">
                      <var:string label:value="After"/>
                    </md-option>
                    <md-option value="between">
                      <var:string label:value="Between"/>
                    </md-option>
                </md-select>

                <md-datepicker class="md-text search-right-space" 
                  ng-model="dialogCtrl.mainController.searchForm.dateStart"
                  md-hide-icons="calendar"
                  ng-change="dialogCtrl.mainController.changeDate()"
                  ng-show="['before', 'after', 'between'].indexOf(dialogCtrl.mainController.searchForm.date) != -1">
                </md-datepicker>

                <div class="search-right-space search-and" ng-show="['between'].indexOf(dialogCtrl.mainController.searchForm.date) != -1">
                  <var:string label:value="and"/>
                </div>

                <md-datepicker class="md-text search-right-space " 
                  ng-model="dialogCtrl.mainController.searchForm.dateEnd"
                  md-hide-icons="calendar"
                  ng-change="dialogCtrl.mainController.changeDate()"
                  ng-show="['between'].indexOf(dialogCtrl.mainController.searchForm.date) != -1">
                </md-datepicker>
              </div>

              <md-input-container class="advanced-search-full">
                <label><var:string label:value="Bcc"/></label>
                <input type="text" var:value="dialogCtrl.mainController.searchForm.bcc" ng-model="dialogCtrl.mainController.searchForm.bcc" ng-keyup="dialogCtrl.mainController.searchFieldChange($event)"/>
              </md-input-container>

              <div class="search-inline">
                <md-input-container class="md-text search-right-space">
                  <label><var:string label:value="Message size"/></label>
                  <input type="number" var:value="dialogCtrl.mainController.searchForm.size" ng-model="dialogCtrl.mainController.searchForm.size" ng-keyup="dialogCtrl.mainController.searchFieldChange($event)"/>
                </md-input-container>

                <md-select ng-model="dialogCtrl.mainController.searchForm.sizeOperator" class="search-right-space">
                    <md-option value="&gt;">
                      &gt;
                    </md-option>
                    <md-option value="&lt;">
                      &lt;
                    </md-option>
                </md-select>
                <md-select ng-model="dialogCtrl.mainController.searchForm.sizeUnit" class="search-right-space">
                    <md-option value="kb">
                      <var:string label:value="KiB"/>
                    </md-option>
                    <md-option value="mb">
                      <var:string label:value="MiB"/>
                    </md-option>
                    <md-option value="gb">
                      <var:string label:value="GiB"/>
                    </md-option>
                </md-select>
              </div>


              <md-checkbox
                            ng-model="dialogCtrl.mainController.searchForm.attachements"
                            ng-true-value="1"
                            ng-false-value="0"
                            label:aria-label="With attachments">
                <var:string label:value="With attachments"/>
              </md-checkbox>

              <md-checkbox
                            ng-model="dialogCtrl.mainController.searchForm.favorite"
                            ng-true-value="1"
                            ng-false-value="0"
                            label:aria-label="In favorites">
                <var:string label:value="In favorites"/>
              </md-checkbox>

              <md-checkbox
                            ng-model="dialogCtrl.mainController.searchForm.unseen"
                            ng-true-value="1"
                            ng-false-value="0"
                            label:aria-label="Unseen only">
                <var:string label:value="Unseen only"/>
              </md-checkbox>

              <md-chips class="sg-readonly advanced-search-full"
                        sg-focus-on="flags"
                        ng-model="dialogCtrl.mainController.searchForm.flags"
                        md-transform-chip="$chip.name">
                <md-chip-template>
                  <span class="sg-chip-color">
                    <span ng-style="{ 'background-color': dialogCtrl.message.$tags[$chip][1] }"><!-- color --></span>
                  </span>
                  <span ng-bind="dialogCtrl.message.$tags[$chip][0] || $chip"><!-- tag --></span>
                </md-chip-template>
                <md-autocomplete
                    md-search-text="dialogCtrl.mainController.searchForm.tags.searchText"
                    md-items="tag in dialogCtrl.message.filterTags(dialogCtrl.mainController.searchForm.tags.searchText, dialogCtrl.mainController.message.flags)"
                    md-no-cache="true"
                    label:placeholder="Add a tag">
                  <md-item-template>
                    <div layout="row" layout-align="start center">
                      <div class="sg-color-chip"
                          ng-style="{ 'background-color': tag.color }"><!-- color --></div>
                      <div md-highlight-text="dialogCtrl.mainController.searchForm.tags.searchText"
                          md-highlight-flags="^i">{{ tag.description }}</div>
                    </div>
                  </md-item-template>
                </md-autocomplete>
              </md-chips>
          </div>
          
              <div class="search-inline advanced-search-full advanced-search-in">
                <div class="pseudo-input-container pseudo-input-container--compact md-flex sg-no-wrap">
                  <label class="pseudo-input-label pseudo-input-label">
                    <var:string label:value="Search messages in"/>
                  </label>
                  <md-select class="pseudo-input-field" label:aria-label="Search messages in" ng-model="dialogCtrl.mailbox.$virtualPath">
                    <md-option ng-value="''">
                      <span ng-bind="dialogCtrl.mainController.accounts[0].name"><!-- main account name --></span>
                    </md-option>
                    <md-option ng-repeat="folder in
                                          dialogCtrl.mainController.accounts[0].$flattenMailboxes()
                                          track by folder.path"
                              ng-value="folder.path">
                      <span ng-class="'sg-child-level-' + folder.level"
                            ng-bind="folder.$displayName"><!-- mailbox name --></span>
                    </md-option>
                  </md-select>
                </div>
                <md-menu>
                  <md-button class="sg-icon-button" label:aria-label="More search options" ng-click="$mdMenu.open()">
                    <md-icon>settings</md-icon>
                  </md-button>
                  <md-menu-content>
                    <md-menu-item>
                      <sg-checkmark ng-model="dialogCtrl.mainController.search.subfolders"
                                    sg-true-value="1"
                                    sg-false-value="0">
                        <var:string label:value="Search subfolders"/>
                      </sg-checkmark>
                    </md-menu-item>
                    <md-menu-divider><!-- divider --></md-menu-divider>
                    <md-menu-item>
                      <md-button ng-click="dialogCtrl.mainController.search.match='AND'">
                        <md-icon label:aria-label="Match all of the following">{{ dialogCtrl.mainController.search.match == 'AND' ? 'check' : null }}</md-icon>
                        <var:string label:value="Match all of the following"/>
                      </md-button>
                    </md-menu-item>
                    <md-menu-item>
                      <md-button ng-click="dialogCtrl.mainController.search.match='OR'">
                        <md-icon label:aria-label="Match any of the following">{{ dialogCtrl.mainController.search.match == 'OR' ? 'check' : null }}</md-icon>
                        <var:string label:value="Match any of the following"/>
                      </md-button>
                    </md-menu-item>
                  </md-menu-content>
                </md-menu>
              </div>
        
      </md-dialog-content>
      <md-dialog-actions>
        <md-button 
                  class="md-warn"
                  label:aria-label="Cancel"
                  ng-click="dialogCtrl.closeDialog()">
                  <var:string label:value="Cancel"/>
        </md-button>
        <md-button 
                  label:aria-label="Reset"
                  ng-click="dialogCtrl.mainController.reset()">
                  <var:string label:value="Reset"/>
        </md-button>
        <div class="md-flex"><!-- spacer --></div>
        <md-button 
                  label:aria-label="Search"
                  ng-click="dialogCtrl.search()">
                  <var:string label:value="Search"/>
        </md-button>         
      </md-dialog-actions>
    </md-dialog>
  </script>
  <!-- Remove old emails -->
  <script type="text/ng-template" id="cleanMailbox">
    <md-dialog flex="50" flex-sm="80" flex-xs="100">
      <!-- Toolbar -->
      <md-toolbar>
        <div class="md-toolbar-tools">
          <md-icon class="material-icons sg-icon-toolbar-bg">delete</md-icon>
          <div class="pseudo-input-container md-flex" ng-if="::!dialogCtrl.isMailbox">
            <var:string label:value="Clean folder"/>
          </div>
          <div class="pseudo-input-container md-flex" ng-if="::dialogCtrl.isMailbox">
            <var:string label:value="Clean mailbox"/>
          </div>
          <md-button class="md-icon-button" ng-click="dialogCtrl.closeDialog()">
            <md-icon aria-label="Close dialog">close</md-icon>
          </md-button>
        </div>
      </md-toolbar>

      <!-- Dialog Content -->
      <md-dialog-content class="md-dialog-content">
        <div class="md-dialog-content">
          <h4>
            {{ dialogCtrl.name }}
          </h4>

          <md-input-container class="md-block">
            <md-checkbox ng-model="dialogCtrl.form.permanentlyDelete" label:aria-label="Delete permanently (do not use trash)">
                <var:string label:value="Delete permanently (do not use trash)"/>
            </md-checkbox>
          </md-input-container>

          <md-input-container class="md-block">
            <md-checkbox ng-model="dialogCtrl.form.applyToSubfolders" label:aria-label="Apply to subfolders">
              <var:string label:value="Apply to subfolders"/>
            </md-checkbox>
          </md-input-container>

          <md-input-container class="md-block">
            <label><var:string label:value="Delete e-mails older than"/></label>
            <md-select ng-model="dialogCtrl.form.filterDuration">
              <md-option value="3m"><var:string label:value="3 months"/></md-option>
              <md-option value="6m"><var:string label:value="6 months"/></md-option>
              <md-option value="9m"><var:string label:value="9 months"/></md-option>
              <md-option value="1y"><var:string label:value="1 year"/></md-option>
              <md-option value="custom"><var:string label:value="Custom"/></md-option>
            </md-select>
          </md-input-container>

          <md-input-container class="md-block" ng-show="['custom'].indexOf(dialogCtrl.form.filterDuration) != -1">
          <label><var:string label:value="Date"/></label>
            <md-datepicker class="md-text" 
                ng-model="dialogCtrl.form.filterDurationDate"
                md-hide-icons="calendar"
                md-max-date="dialogCtrl.maxDate"
                ng-change="dialogCtrl.mainController.changeDate()">
              </md-datepicker>
          </md-input-container>

          <md-input-container class="md-block" ng-show="dialogCtrl.isWarningDisplayed()">
            <md-checkbox ng-model="dialogCtrl.form.confirmDelete" label:aria-label="You are about to permanently delete some messages. Are you sure you want to proceed with this action?">
              <span class="clean-mailbox-warn"><var:string label:value="You are about to permanently delete some messages. Are you sure you want to proceed with this action?" /></span>
            </md-checkbox>
          </md-input-container>
        </div>
      </md-dialog-content>

      <!-- Dialog Actions -->
      <md-dialog-actions>
        <md-button class="md-warn" ng-click="dialogCtrl.closeDialog()">
          <var:string label:value="Cancel" />
        </md-button>
        <div class="sg-progress-linear-bottom"
                     ng-show="dialogCtrl.isLoading()">
                  <md-progress-linear class="md-accent"
                                      md-mode="indeterminate"><!-- progress --></md-progress-linear>
                </div>
        <md-button class="md-primary" ng-disabled="dialogCtrl.isApplyDisabled()" ng-click="dialogCtrl.apply()">
          <var:string label:value="Apply" />
        </md-button>
      </md-dialog-actions>
    </md-dialog>
  </script>
</container>
