Skip to content

Commit

Permalink
add additional PSTTask recurrence props
Browse files Browse the repository at this point in the history
  • Loading branch information
shalomscott committed Oct 2, 2020
1 parent dde1ec0 commit fde0106
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/OutlookProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,12 @@ export enum OutlookProperties {
PidTagWeddingAnniversary = 0x3a41,
PidLidPercentComplete = 0x00008102,
PidLidTaskStatus = 0x00008101,
PidLidTaskDeadOccurrence = 0x00008109,
PidLidTaskDateCompleted = 0x0000810f,
PidLidTaskActualEffort = 0x00008110,
PidLidTaskEstimatedEffort = 0x00008111,
PidLidTaskVersion = 0x00008112,
PidLidTaskRecurrence = 0x00008116,
PidLidTaskComplete = 0x0000811c,
PidLidTaskOwner = 0x0000811f,
PidLidTaskAssigner = 0x00008121,
Expand Down
30 changes: 30 additions & 0 deletions src/PSTTask.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { PSTDescriptorItem } from './PSTDescriptorItem.class'
import { PSTMessage } from './PSTMessage.class'
import { PSTTableBC } from './PSTTableBC.class'
import { PSTFile } from './PSTFile.class'
import { RecurrencePattern } from './RecurrencePattern.class'

export class PSTTask extends PSTMessage {
/**
Expand Down Expand Up @@ -215,6 +216,35 @@ export class PSTTask extends PSTMessage {
)
}

/**
* https://docs.microsoft.com/en-us/office/client-developer/outlook/mapi/pidlidtaskrecurrence-canonical-property
* @type {RecurrencePattern}
* @memberof PSTTask
*/
public get taskRecurrencePattern(): RecurrencePattern | null {
const recurrenceBLOB = this.getBinaryItem(
this.pstFile.getNameToIdMapItem(
OutlookProperties.PidLidTaskRecurrence,
PSTFile.PSETID_Task
)
)
return recurrenceBLOB && new RecurrencePattern(recurrenceBLOB)
}

/**
* https://docs.microsoft.com/en-us/office/client-developer/outlook/mapi/pidlidtaskdeadoccurrence-canonical-property
* @type {boolean}
* @memberof PSTTask
*/
public get taskDeadOccurrence(): boolean {
return this.getBooleanItem(
this.pstFile.getNameToIdMapItem(
OutlookProperties.PidLidTaskDeadOccurrence,
PSTFile.PSETID_Task
)
)
}

/**
* Indicates the role of the current user relative to the task.
* https://msdn.microsoft.com/en-us/library/office/cc842113.aspx
Expand Down
101 changes: 101 additions & 0 deletions src/RecurrencePattern.class.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
const OFFSETS = {
RecurFrequency: 4,
PatternType: 6,
FirstDateTime: 10,
Period: 14,
PatternTypeSpecific: 22,
EndType: 22,
OccurrenceCount: 26,
FirstDOW: 30,
StartDate: -8,
EndDate: -4,
}

export enum RecurFrequency {
Daily = 0x200a,
Weekly = 0x200b,
Monthly = 0x200c,
Yearly = 0x200d,
}

export enum PatternType {
Day = 0x0000,
Week = 0x0001,
Month = 0x0002,
MonthEnd = 0x0004,
MonthNth = 0x0003,
}

export enum EndType {
AfterDate = 0x00002021,
AfterNOccurrences = 0x00002022,
NeverEnd = 0x00002023,
}

export class RecurrencePattern {
recurFrequency: RecurFrequency
patternType: PatternType
firstDateTime: Date
period: number
endType: EndType
occurrenceCount: number
firstDOW: number
startDate: Date
endDate: Date

constructor(private buffer: Buffer) {
const bufferEnd = buffer.length
let patternTypeOffset = 0

this.recurFrequency = this.readInt(OFFSETS.RecurFrequency, 1)
this.patternType = this.readInt(OFFSETS.PatternType, 1)
this.firstDateTime = winToJsDate(this.readInt(OFFSETS.FirstDateTime, 2))
this.period = this.readInt(OFFSETS.Period, 2)

switch (this.patternType) {
case PatternType.Week:
case PatternType.Month:
patternTypeOffset = 4
break
case PatternType.MonthNth:
patternTypeOffset = 8
break
}

this.endType = this.readInt(OFFSETS.EndType + patternTypeOffset, 2)
this.occurrenceCount = this.readInt(
OFFSETS.OccurrenceCount + patternTypeOffset,
2
)
this.firstDOW = this.readInt(OFFSETS.FirstDOW + patternTypeOffset, 2)
this.startDate = winToJsDate(this.readInt(bufferEnd + OFFSETS.StartDate, 2))
this.endDate = winToJsDate(this.readInt(bufferEnd + OFFSETS.EndDate, 2))
}

public toJSON(): any {
return {
recurFrequency: RecurFrequency[this.recurFrequency],
patternType: PatternType[this.patternType],
firstDateTime: this.firstDateTime,
period: this.period,
endType: EndType[this.endType],
occurrenceCount: this.occurrenceCount,
firstDOW: this.firstDOW,
startDate: this.startDate,
endDate: this.endDate,
}
}

private readInt(offset: number, size: 1 | 2) {
switch (size) {
case 1:
return this.buffer.readInt16LE(offset)
case 2:
return this.buffer.readInt32LE(offset)
}
}
}

function winToJsDate(dateInt: number): Date {
return new Date(dateInt * 60 * 1000 - 1.16444736e13)
}

0 comments on commit fde0106

Please sign in to comment.